def is_active(link, req_path):
    current = Page.get_page(req_path)
    while(current != None):
        if (current == link):
            return "active"
        current = current.parent
    return "no-active"
def title(path, dynamic_title = ''):
    page = Page.get_page(path)
    if (page == None): return dynamic_title;
    
    title = page.title
    if (page.html_title != '' and page.html_title != None): title = page.html_title
    
    if (dynamic_title):
        return '%s - %s' % (title, dynamic_title)
    return title
def submenu(path):
    parent = Page.get_page(path)
    if (parent):
        while(parent.parent != None):
            parent = parent.parent
        pages = Page.objects.filter(parent = parent, order__isnull = False).order_by('order')
        for page in pages:
            if (not page.is_active()):
                pages = pages.exclude(pk = page.id)
        return {'pages': pages, 'path': path}
    else:
        return
def subsubmenu(context, path, form = None):
    if not form and context.has_key('form'):
        form = context['form']
    parent = Page.get_page(path)
    if (parent and parent.parent):
        while(parent.parent.parent != None):
            parent = parent.parent
        pages = Page.objects.filter(parent = parent, order__isnull = False).order_by('order')
        for page in pages:
            if (not page.is_active()):
                pages = pages.exclude(pk = page.id)
        return {'pages': pages, 'path': path, 'form': form, 'STATIC_URL': context['STATIC_URL']}
    else:
        return {'form': form, 'STATIC_URL': context['STATIC_URL']}
def meta(path, meta = []):
    page = Page.get_page(path)
    if (page == None): return {'meta_tags': None}
    meta_tags = list(page.meta_data.all())
    meta_tags += meta
    return {'meta_tags': meta_tags}