1
1
from django .conf import settings
2
2
3
- import traceback
4
- import sys
5
3
import re
6
4
5
+
7
6
class Menu (object ):
8
7
"""
9
8
Menu is a class that generates menus
@@ -45,7 +44,7 @@ def load_menus(c):
45
44
"""
46
45
47
46
# we don't need to do this more than once
48
- if c .loaded == True :
47
+ if c .loaded :
49
48
return
50
49
51
50
# loop through our INSTALLED_APPS
@@ -56,7 +55,7 @@ def load_menus(c):
56
55
57
56
menu_module = '%s.menus' % app
58
57
try :
59
- __import__ (menu_module , fromlist = ["menu" , ])
58
+ __import__ (menu_module , fromlist = ["menu" ])
60
59
except ImportError :
61
60
pass
62
61
@@ -69,8 +68,8 @@ def sort_menus(c):
69
68
their weight
70
69
"""
71
70
for name in c .items :
72
- if c .sorted [name ] != True :
73
- c .items [name ].sort (cmp = lambda x ,y : cmp (x .weight , y .weight ))
71
+ if not c .sorted [name ]:
72
+ c .items [name ].sort (cmp = lambda x , y : cmp (x .weight , y .weight ))
74
73
c .sorted [name ] = True
75
74
76
75
@classmethod
@@ -96,7 +95,7 @@ def process(c, request, name=None):
96
95
curitem = None
97
96
for item in c .items [name ]:
98
97
item .process (request )
99
- if item .visible == True :
98
+ if item .visible :
100
99
item .selected = False
101
100
if item .match_url (request ):
102
101
if curitem is None or len (curitem .url ) < len (item .url ):
@@ -133,7 +132,7 @@ class MenuItem(object):
133
132
menu (children).
134
133
"""
135
134
136
- def __init__ (self , title , url , children = [], weight = 1 , check = None ,
135
+ def __init__ (self , title , url , children = [], weight = 1 , check = None ,
137
136
visible = True , slug = None , exact_url = False , ** kwargs ):
138
137
"""
139
138
MenuItem constructor
@@ -232,11 +231,7 @@ def check_children(self, request):
232
231
233
232
def check_check (self , request ):
234
233
if callable (self .check ):
235
- check = self .check (request )
236
- if check != True :
237
- self .visible = False
238
- else :
239
- self .visible = True
234
+ self .visible = self .check (request )
240
235
241
236
def check_title (self , request ):
242
237
if callable (self ._title ):
0 commit comments