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

from project.models import Notification


def search_form(request):
    egg_pages = (
        (81, 'C', 1),
        (83, 'R', 2),
        (95, 'E', 3),
        (105, 'D', 4),
        (99, 'O', 5),
    )
    return {
        'egg_pages': egg_pages,
        '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
