+class RecurseNavigationNode(RecurseTreeNode):
+ def __init__(self, template_nodes, instance_var):
+ self.template_nodes = template_nodes
+ self.instance_var = instance_var
+
+ def _render_node(self, context, node, request):
+ bits = []
+ context.push()
+ for child in node.get_children():
+ context['node'] = child
+ bits.append(self._render_node(context, child, request))
+ context['node'] = node
+ context['children'] = mark_safe(u''.join(bits))
+ context['active'] = node.is_active(request)
+ rendered = self.template_nodes.render(context)
+ context.pop()
+ return rendered
+
+ def render(self, context):
+ try:
+ request = context['request']
+ except KeyError:
+ return ''
+
+ instance = self.instance_var.resolve(context)
+ roots = cache_tree_children(Navigation.objects.closest_navigation(instance))
+ bits = [self._render_node(context, node, request) for node in roots]
+ return ''.join(bits)