PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/treemenus/templatetags/tree_menu_tags.py

http://github.com/plushcms/PlushCMS
Python | 42 lines | 27 code | 12 blank | 3 comment | 3 complexity | 6a60b89c4e3efaab453b2a3078f6f8fe MD5 | raw file
 1# -*- coding: utf-8 -*-
 2
 3from django import template
 4from django.template.defaulttags import url
 5from django.template.defaulttags import URLNode
 6from django.template import Node
 7
 8from plushcms.treemenus.models import Menu
 9from plushcms.treemenus.models import MenuItem
10from plushcms.treemenus.config import APP_LABEL
11
12from django.template import TOKEN_BLOCK
13from django.template import Token
14
15register = template.Library()
16
17# 16.02.2011 - dodany try except
18def show_menu(context, menu_name, menu_type = None):
19    try:
20        menu = Menu.objects.get(name = menu_name)
21    except:
22        return None
23    else:
24        context["menu"] = menu
25
26        if menu_type:
27            context["menu_type"] = menu_type
28
29        return context
30
31register.inclusion_tag("%s/menu.html" % APP_LABEL, takes_context = True)(show_menu)
32
33def show_menu_item(context, menu_item):
34    if not isinstance(menu_item, MenuItem):
35        raise template.TemplateSyntaxError, "Podany argument musi być obiektem MenuItem."
36
37    context["menu_item"] = menu_item
38
39    return context
40
41register.inclusion_tag("%s/menu_item.html" % APP_LABEL, takes_context = True)(show_menu_item)
42# 06.03.2011 - usunięto ReverseNamedURLNode, reverse_named_ulr i jego rejestracja