1 from django import template
2 from forum.modules import ui
4 register = template.Library()
7 class LoadRegistryNode(template.Node):
8 def __init__(self, registry, separator):
9 self.registry = registry
10 self.separator = separator
12 def render(self, context):
13 separator = self.separator.render(context)
16 for ui_object in self.registry:
17 if ui_object.can_render(context):
20 result += ui_object.render(context)
26 def loadregistry(parser, token):
28 tag_name, registry = token.split_contents()
30 raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]
32 registry = ui.get_registry_by_name(registry)
33 separator = parser.parse(('endloadregistry',))
34 parser.delete_first_token()
35 return LoadRegistryNode(registry, separator)
38 class LoopRegistryNode(template.Node):
39 def __init__(self, registry, nodelist):
40 self.registry = registry
41 self.nodelist = nodelist
43 def render(self, context):
46 for ui_object in self.registry:
47 if ui_object.can_render(context):
48 ui_object.update_context(context)
49 result += self.nodelist.render(context)
54 def loopregistry(parser, token):
56 tag_name, registry = token.split_contents()
58 raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]
60 registry = ui.get_registry_by_name(registry)
61 nodelist = parser.parse(('endloopregistry',))
62 parser.delete_first_token()
64 return LoopRegistryNode(registry, nodelist)