class HotMenuNode template Node def __init__ self user lang self user

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class HotMenuNode(template.Node):
def __init__(self, user, lang):
self.user = template.Variable(user)
self.lang = template.Variable(lang)
def render(self, context):
context['user'] = self.user.resolve(context)
lang = self.lang.resolve(context)
ct = ContentType.objects.get_for_model(ProductCategory)
context['categories'] = Translation.objects.filter(lang=lang, content_type=ct)
t = template.Template('{% include "hot_menu.html" %}').render(context)
return t
@register.tag
def category_menu(parser, token):
try:
tag_name, user, lang = token.split_contents()
print user, lang
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
return HotMenuNode(user=user, lang=lang)