File tree Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -11,5 +11,12 @@ MENU_SELECT_PARENTS
11
11
their ``selected `` property set to ``True `` if one of their children has its
12
12
``selected `` property set to ``True ``.
13
13
14
+ MENU_HIDE_EMPTY
15
+ -------------------
16
+ **Default: ``False`` **
17
+
18
+ ``MENU_HIDE_EMPTY `` controls if menu items without an explicit ``check `` callback
19
+ should be visible even if they have no children
20
+
14
21
15
22
.. _Django settings file : https://docs.djangoproject.com/en/dev/topics/settings/
Original file line number Diff line number Diff line change @@ -185,18 +185,24 @@ def process(self, request):
185
185
if not self .visible :
186
186
return
187
187
188
+ # evaluate title
188
189
self .check_title (request )
189
- self .check_children (request )
190
190
191
- children = [
192
- kid
193
- for kid in self .children
194
- if kid .visible
195
- ]
191
+ # evaluate children
192
+ visible_children = []
193
+ self .check_children (request )
194
+ for child in self .children :
195
+ child .process (request )
196
+ if child .visible :
197
+ visible_children .append (child )
198
+
199
+ hide_empty = getattr (settings , 'MENU_HIDE_EMPTY' , False )
200
+ if hide_empty and not self .check and not len (visible_children ):
201
+ self .visible = False
202
+ return
196
203
197
204
curitem = None
198
- for item in children :
199
- item .process (request )
205
+ for item in visible_children :
200
206
item .selected = False
201
207
202
208
if item .match_url (request ):
You can’t perform that action at this time.
0 commit comments