X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/0d560fdc9e0351ebe039dcc9d9d14b6b560ba00c..26c548c5fe8c7cc7227b5f38cd27e0278442dd76:/contrib/shipherd/templatetags/shipherd.py diff --git a/contrib/shipherd/templatetags/shipherd.py b/contrib/shipherd/templatetags/shipherd.py index fec700b..019d240 100644 --- a/contrib/shipherd/templatetags/shipherd.py +++ b/contrib/shipherd/templatetags/shipherd.py @@ -2,6 +2,7 @@ from django import template from django.conf import settings from django.utils.safestring import mark_safe from philo.contrib.shipherd.models import Navigation +from philo.models import Node from mptt.templatetags.mptt_tags import RecurseTreeNode, cache_tree_children @@ -17,9 +18,9 @@ class RecurseNavigationNode(RecurseTreeNode): bits = [] context.push() for child in node.get_children(): - context['node'] = child + context['navigation'] = child bits.append(self._render_node(context, child, request)) - context['node'] = node + context['navigation'] = node context['children'] = mark_safe(u''.join(bits)) context['active'] = node.is_active(request) rendered = self.template_nodes.render(context) @@ -33,7 +34,16 @@ class RecurseNavigationNode(RecurseTreeNode): return '' instance = self.instance_var.resolve(context) - roots = cache_tree_children(Navigation.objects.closest_navigation(instance)) + + if isinstance(instance, Node): + qs = Navigation.objects.closest_navigation(instance) + elif hasattr(instance, '__iter__'): + # Is this the right way to check? + qs = instance + else: + return settings.TEMPLATE_STRING_IF_INVALID + + roots = cache_tree_children(qs) bits = [self._render_node(context, node, request) for node in roots] return ''.join(bits) @@ -41,17 +51,17 @@ class RecurseNavigationNode(RecurseTreeNode): @register.tag def recursenavigation(parser, token): """ - Based on django-mptt's recursetree templatetag. In addition to {{ node }} and {{ children }}, + Based on django-mptt's recursetree templatetag. In addition to {{ navigation }} and {{ children }}, sets {{ active }} in the context. - Note that the tag takes one variable, navigation, which is a Navigation instance. + Note that the tag takes one variable, which is a Node instance. Usage: