Added 1.2.X compatibility to shipherd LazyNavigationRecurser.
[philo.git] / contrib / shipherd / templatetags / shipherd.py
index 9a4d74c..6e36126 100644 (file)
@@ -1,8 +1,9 @@
-from django import template
+from django import template, VERSION as django_version
 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 django.utils.safestring import mark_safe
 from django.utils.translation import ugettext as _
 
 
@@ -59,11 +60,15 @@ class LazyNavigationRecurser(object):
                        context['item'] = item
                        context['children'] = self.__class__(self.template_nodes, item.get_children(), context, request)
                        
+                       # Django 1.2.X compatibility - a lazy recurser will not be called if accessed as a template variable.
+                       if django_version < (1,3):
+                               context['children'] = context['children']()
+                       
                        # Then render the nodelist bit by bit.
                        for node in self.template_nodes:
                                bits.append(node.render(context))
                context.pop()
-               return ''.join(bits)
+               return mark_safe(''.join(bits))
 
 
 class RecurseNavigationNode(template.Node):
@@ -166,6 +171,4 @@ def navigation_host(node, key):
        try:
                return Navigation.objects.filter(node__in=node.get_ancestors(include_self=True), key=key).order_by('-node__level')[0].node
        except:
-               if settings.TEMPLATE_DEBUG:
-                       raise
                return node
\ No newline at end of file