Commits

Denis Costa  committed 2ea19b2

closed #1 Corrigido problema com permissão nos submenus.

  • Participants
  • Parent commits 478c6f7

Comments (0)

Files changed (2)

File menu/context_processors.py

 from django.conf import settings
 
-def _prepare_menu(request, raw_menu):    
+#ok
+def _prepare_menu(raw_menu):
+    menu = []
     for i in raw_menu:
+        i = list(i)
+        if isinstance(i[1], tuple):
+            i[1] = _prepare_menu(i[1])
+            i[1] = list(i[1])
         if len(i) == 2:
             i.append(None)
+        menu.append(i)
+    return menu
 
+def _check_permissions(request, raw_menu):
     menu = []
-    path = request.path[1:].lower()
 
     for item in raw_menu:
         label, uri, permission = item
         if permission == None or request.user.has_perm(permission):
+            if isinstance(uri, list):
+                uri = tuple(_check_permissions(request, uri))
             menu.append((label, uri))
     return menu
 
 def menu(request):
     raw_menu = [list(i) for i in settings.MENU]
-    return {'menu': _prepare_menu(request, raw_menu)}
+    return {'menu': _check_permissions(request, _prepare_menu(raw_menu))}
 
 def submenu(request):
     raw_menu = [list(i) for i in settings.MENU]
     for item in raw_menu:
         if request.path[1:].startswith(item[0].lower()) and isinstance(item[1], tuple):
             submenu = item[1]
-    return {'submenu': submenu}
+    return {'submenu': _check_permissions(request, _prepare_menu(submenu))}

File menu/templatetags/menu.py

 
 def _menuing(raw_menu, old_label=''):
     menu = ''
-    print raw_menu
     for label, link in raw_menu:
         if isinstance(link, tuple):
             if old_label: