Commits

Tino de Bruijn committed 00669e7

Conditionals now can be methods, which makes it a little easier to override them

Comments (0)

Files changed (2)

django_nav/base.py

     args = ()
     kwargs ={}
     options = []
-    conditional = {'function': None, 'args': [], 'kwargs': {}}
-
+    conditional = True
+    conditional_args = ()
+    conditional_kwargs = {}
+    
     def active_if(self, url, path):
         return path == url
 
         if self.view:
             return reverse(self.view, args=self.args, kwargs=self.kwargs,
                            prefix='/')
-
         return '#'
 
 class NavOption(NavType):

django_nav/templatetags/nav.py

                     self.kwargs[key] = resolve(value, self.context)
                 nav.kwargs = self.kwargs
 
-            if self.check_conditional(nav):
+            if not self.check_conditional(nav):
                 continue
 
             nav.option_list = self.build_options(nav.options)
             if self.kwargs:
                 option.kwargs = self.kwargs
 
-            if self.check_conditional(option):
+            if not self.check_conditional(option):
                 continue
 
             option.active = False
         return options
 
     def check_conditional(self, of):
-        conditional = of.conditional.get('function')
-        return conditional and not conditional(self.context,
-                                           *of.conditional['args'],
-                                           **of.conditional['kwargs'])
+        conditional = of.conditional
+        if not callable(conditional):
+            return conditional
+        return conditional(self.context, *of.conditional_args, 
+                                                **of.conditional_kwargs)
 
 @register.tag
 def get_nav(parser, token):