Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc2cf65

Browse files
fsbraunstefanw
andauthored
Fix: Cut children from inactive nodes when level is less or equal to 0 (#8322) (#8324)
It can be less than zero when the from_level is greater than zero. Co-authored-by: Stefan Wehrmeyer <[email protected]>
1 parent c4760c3 commit bc2cf65

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cms/tests/test_menu.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ def test_menu_failfast_on_invalid_usage(self):
227227
tpl = Template("{% load menu_tags %}{% show_menu 0 0 0 0 'menu/menu.html' child %}")
228228
self.assertRaises(TemplateSyntaxError, tpl.render, context)
229229

230+
def test_show_menu_cut_inactive(self):
231+
root = self.get_page(2)
232+
context = self.get_context(page=root)
233+
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}")
234+
tpl.render(context)
235+
nodes = context["children"]
236+
self.assertEqual(len(nodes), 2)
237+
self.assertEqual(len(nodes[0].children), 1)
238+
self.assertEqual(len(nodes[1].children), 0)
239+
230240
def test_show_submenu_nephews(self):
231241
page_2 = self.get_page(2)
232242
context = self.get_context(path=page_2.get_absolute_url(), page=page_2)

menus/templatetags/menu_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def cut_after(node, levels, removed=None):
3232
if removed is not None:
3333
raise TypeError("menus.template_tags.cut_after() does not accept 'removed' list argument")
3434

35-
if levels == 0:
35+
if levels <= 0:
3636
node.children = []
3737
else:
3838
for child in node.children:

0 commit comments

Comments
 (0)