Skip to content

Commit

Permalink
Merge pull request #4175 from yakky/feature/merge_4107
Browse files Browse the repository at this point in the history
Merge #4107 and backport #3509
  • Loading branch information
yakky committed Jun 10, 2015
2 parents 8bdef8d + 58957a6 commit 4a16b69
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cms/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ class SoftRootCutter(Modifier):

def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
# only apply this modifier if we're pre-cut (since what we do is cut)
if post_cut:
# or if no id argument is provided, indicating {% show_menu_below_id %}
if post_cut or root_id:
return nodes
selected = None
root_nodes = []
Expand Down
131 changes: 131 additions & 0 deletions cms/tests/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,107 @@ def test_not_in_navigation(self):
child = children[0]
self.assertEqual(child.id, c.publisher_public.id)

def test_menu_beyond_soft_root(self):
"""
Test for issue 4107
Build the following tree:
A
|-B (soft_root)
|-C
"""
stdkwargs = {
'template': 'nav_playground.html',
'language': 'en',
'published': True,
'in_navigation': True,
}
a = create_page('A', reverse_id='a', **stdkwargs)
b = create_page('B', parent=a, soft_root=True, **stdkwargs)
c = create_page('C', parent=b, **stdkwargs)

context = self.get_context(a.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
tpl.render(context)
nodes = context['children']
# check whole menu
self.assertEqual(len(nodes), 1)
a_node = nodes[0]
self.assertEqual(a_node.id, a.publisher_public.pk) # On A, show from A
self.assertEqual(len(a_node.children), 1)
b_node = a_node.children[0]
self.assertEqual(b_node.id, b.publisher_public.pk)
self.assertEqual(len(b_node.children), 1)
c_node = b_node.children[0]
self.assertEqual(c_node.id, c.publisher_public.pk)
self.assertEqual(len(c_node.children), 0)

context = self.get_context(b.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
tpl.render(context)
nodes = context['children']
# check whole menu
self.assertEqual(len(nodes), 1)
b_node = nodes[0]
self.assertEqual(b_node.id, b.publisher_public.pk) # On B, show from B
self.assertEqual(len(b_node.children), 1)
c_node = b_node.children[0]
self.assertEqual(c_node.id, c.publisher_public.pk)
self.assertEqual(len(c_node.children), 0)

context = self.get_context(c.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
tpl.render(context)
nodes = context['children']
# check whole menu
self.assertEqual(len(nodes), 1)
b_node = nodes[0]
self.assertEqual(b_node.id, b.publisher_public.pk) # On C, show from B
self.assertEqual(len(b_node.children), 1)
c_node = b_node.children[0]
self.assertEqual(c_node.id, c.publisher_public.pk)
self.assertEqual(len(c_node.children), 0)

context = self.get_context(a.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
tpl.render(context)
nodes = context['children']
# check whole menu
self.assertEqual(len(nodes), 1)
b_node = nodes[0]
self.assertEqual(b_node.id, b.publisher_public.pk) # On A, show from B (since below A)
self.assertEqual(len(b_node.children), 1)
c_node = b_node.children[0]
self.assertEqual(c_node.id, c.publisher_public.pk)
self.assertEqual(len(c_node.children), 0)

context = self.get_context(b.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
tpl.render(context)
nodes = context['children']
# check whole menu
self.assertEqual(len(nodes), 1)
b_node = nodes[0]
self.assertEqual(b_node.id, b.publisher_public.pk) # On B, show from B (since below A)
self.assertEqual(len(b_node.children), 1)
c_node = b_node.children[0]
self.assertEqual(c_node.id, c.publisher_public.pk)
self.assertEqual(len(c_node.children), 0)

context = self.get_context(c.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
tpl.render(context)
nodes = context['children']
# check whole menu
self.assertEqual(len(nodes), 1)
b_node = nodes[0]
self.assertEqual(b_node.id, b.publisher_public.pk) # On C, show from B (since below A)
self.assertEqual(len(b_node.children), 1)
c_node = b_node.children[0]
self.assertEqual(c_node.id, c.publisher_public.pk)
self.assertEqual(len(c_node.children), 0)

def test_not_in_navigation_num_queries(self):
"""
Test for issue 521
Expand Down Expand Up @@ -959,6 +1060,36 @@ def test_not_in_navigation_num_queries(self):
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
tpl.render(context)

def test_menu_in_soft_root(self):
"""
Test for issue 3504
Build the following tree:
A
|-B
C (soft_root)
"""
a = create_page('A', 'nav_playground.html', 'en', published=True,
in_navigation=True, reverse_id='a')
b = create_page('B', 'nav_playground.html', 'en', parent=a,
published=True, in_navigation=True)
c = create_page('C', 'nav_playground.html', 'en', published=True,
in_navigation=True, soft_root=True)
context = self.get_context(a.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' %}")
tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
node = nodes[0]
self.assertEqual(node.id, b.publisher_public.id)
context = self.get_context(c.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' %}")
tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
node = nodes[0]
self.assertEqual(node.id, b.publisher_public.id)

class ViewPermissionMenuTests(SettingsOverrideTestCase):
settings_overrides = {
Expand Down
5 changes: 3 additions & 2 deletions docs/reference/navigation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ You can give it the same optional parameters as ``show_menu``::
{% show_menu_below_id "meta" 0 100 100 100 "myapp/menu.html" %}
</ul>

Note that soft roots will not affect the menu when
using ``show_menu_below_id``.
Unlike :ttag:`show_menu`, however, soft roots will not affect the menu when
using :ttag:`show_menu_below_id`.


.. templatetag:: show_sub_menu

Expand Down
2 changes: 2 additions & 0 deletions menus/menu_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def _build_nodes(self, request, site_id):
for menu_class_name in self.menus:
menu = self.menus[menu_class_name]
try:
if isinstance(menu, type):
menu = menu()
nodes = menu.get_nodes(request)
except NoReverseMatch:
# Apps might raise NoReverseMatch if an apphook does not yet
Expand Down

0 comments on commit 4a16b69

Please sign in to comment.