menu: fix items appearing in menus set with a specifig root (#10562)
This commit is contained in:
parent
462aada3f8
commit
ea1d6abfcb
|
@ -17,7 +17,10 @@
|
|||
from django.template.loader import get_template
|
||||
|
||||
def render_menu(context, level=0, root_page=None, depth=1):
|
||||
context = get_menu_context(context, level=level, current_page=root_page, depth=depth)
|
||||
context['root_page'] = root_page
|
||||
if root_page:
|
||||
level = len(root_page.get_parents_and_self())
|
||||
context = get_menu_context(context, level=level, current_page=None, depth=depth)
|
||||
template = get_template('combo/menu.html')
|
||||
return template.render(context)
|
||||
|
||||
|
@ -25,7 +28,18 @@ def get_menu_context(context, level=0, current_page=None, depth=1):
|
|||
context['depth'] = depth
|
||||
if current_page is None:
|
||||
current_page = context['page']
|
||||
page_of_level = current_page.get_page_of_level(level)
|
||||
|
||||
if 'root_page' in context:
|
||||
# if the menu is anchored at a specific root page, we make sure the
|
||||
# current page is in the right path, otherwise we fall back to using
|
||||
# the root page as base.
|
||||
ariane = current_page.get_parents_and_self()
|
||||
if not context.get('root_page') in ariane:
|
||||
page_of_level = context['root_page']
|
||||
else:
|
||||
page_of_level = current_page.get_page_of_level(level)
|
||||
else:
|
||||
page_of_level = current_page.get_page_of_level(level)
|
||||
if level == -1:
|
||||
# get children
|
||||
elements = current_page.get_children()
|
||||
|
@ -37,7 +51,10 @@ def get_menu_context(context, level=0, current_page=None, depth=1):
|
|||
context['menuitems'] = []
|
||||
return context
|
||||
else:
|
||||
elements = page_of_level.get_siblings()
|
||||
if page_of_level is context.get('root_page'):
|
||||
elements = page_of_level.get_children()
|
||||
else:
|
||||
elements = page_of_level.get_siblings()
|
||||
menuitems = []
|
||||
for element in elements:
|
||||
if element.exclude_from_navigation:
|
||||
|
|
Loading…
Reference in New Issue