11fdb44643720af1d286dc297770516621a841c0
[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_navigation(node):
11         return Navigation.objects.closest_navigation(node)
12
13 @register.filter
14 def is_active(navigation, request):
15         """
16         Returns true if the navigation is considered `active`.
17         
18         But what does "active" mean? Should this be defined on the model instead, perhaps?
19         """
20         try:
21                 if navigation.target_node == request.node:
22                         if request.path == navigation.target_url:
23                                 return True
24                         return False
25                 if navigation.target_url in request.path:
26                         return True
27         except:
28                 pass
29         return False