from django import template
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from infopages.models import InfoPage

register = template.Library()

@register.inclusion_tag('infopages/infopage_listing.html')
def infopage_listing(infopage,selected):
    return {'infopage':infopage,'selected':selected}

@register.inclusion_tag('infopages/infopage_index.html')
def infopage_index(selected):
    root=selected.branch().reverse()[0]
    return {'root':root,'top_level':[root],'selected':selected}

@register.inclusion_tag('infopages/infopage_all_index.html')
def infopage_all_index(selected):
    return {'top_level':InfoPage.objects.toplevel(),'selected':selected}

@register.filter('in')
def is_in(obj, iterable):
    return obj in iterable

@register.inclusion_tag('infopages/infopage_menu.html')
def infopage_menu():
    infopages = InfoPage.objects.live().order_by('order')
    return {'infopages':infopages,}

