Tweaked admin and models. Added filters to manage navigation display.
[philo.git] / contrib / navigation / templatetags / navigation.py
1 from django import template
2 from django.conf import settings
3 from philo.contrib.navigation.models import Navigation
4
5
6 register = template.Library()
7
8
9 @register.filter
10 def get_descendants(roots):
11         qs = None
12         for root in roots:
13                 root_qs = root.get_descendants(include_self=True).complex_filter({'%s__lte' % root._mptt_meta.level_attr: root.get_level() + root.depth}).exclude(depth__isnull=True)
14                 if qs is None:
15                         qs = root_qs
16                 else:
17                         qs |= root_qs
18         return qs
19
20 @register.filter
21 def is_active(navigation, request):
22         """
23         Returns true if the navigation is considered `active`.
24         
25         But what does "active" mean? Should this be defined on the model instead, perhaps?
26         """
27         try:
28                 if navigation.target_node == request.node:
29                         if request.path == navigation.target_url:
30                                 return True
31                         return False
32                 if navigation.target_url in request.path:
33                         return True
34         except:
35                 pass
36         return False