from cms.models import Page
from haystack.forms import ModelSearchForm

from project.models import Notification


def search_form(request):
    return {'search_form': ModelSearchForm}


def notification(request):
    return {'notification': Notification.objects.filter(published=True).first()}


def new_page_amount(request):
    tracked_pages = ['news', 'calendar']
    context = {}

    for tracked_page in tracked_pages:
        try:
            page = Page.objects.public().get(reverse_id=tracked_page)
            id = 'new_{}_amount'.format(tracked_page)
            context.update({
                id: page.get_child_pages().count()
            })
        except Page.DoesNotExist:
            pass

    return context
