Skip to content

Commit

Permalink
Correctly parse a deeper menu structure (#133)
Browse files Browse the repository at this point in the history
Co-authored-by: Andor Goetzendorff <ruxkor@hotmail.com>
  • Loading branch information
kytta and ruxkor authored Jun 27, 2023
2 parents e89ed4b + 07d87ba commit 0aa0e09
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions simple_menu/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,20 @@ def process(c, request, name=None):
# determine if we should apply 'selected' to parents when one of their
# children is the 'selected' menu
if getattr(settings, 'MENU_SELECT_PARENTS', False):
def is_child_selected(item):
for child in item.children:
if child.selected or is_child_selected(child):
return True
def get_path_selected(item, parents):
if item.selected:
return parents + [item]
else:
for child in item.children:
path_selected = get_path_selected(child, parents + [item])
if path_selected:
return path_selected

for item in visible:
if is_child_selected(item):
item.selected = True
path_selected = get_path_selected(item, [])
if path_selected:
for item_selected in path_selected:
item_selected.selected = True

return visible

Expand Down

0 comments on commit 0aa0e09

Please sign in to comment.