Permalink
Browse files

show menu below id working

  • Loading branch information...
1 parent ffcd359 commit 27b30c236d8fd8e7de4864cbc5816b4695f58fd3 @digi604 digi604 committed Jan 15, 2010
Showing with 30 additions and 8 deletions.
  1. +1 −1 cms/menu.py
  2. +9 −4 cms/tests/menu.py
  3. +4 −2 menus/base.py
  4. +5 −1 menus/menu_pool.py
  5. +11 −0 menus/templatetags/menu_tags.py
View
@@ -51,7 +51,7 @@ def get_nodes(self, request):
def page_to_node(self, page):
attr = {}
- n = NavigationNode(page.get_menu_title(), page.get_absolute_url(), "cms", page.pk, page.parent_id, "cms", attr, page.soft_root, page.login_required)
+ n = NavigationNode(page.get_menu_title(), page.get_absolute_url(), "cms", page.pk, page.parent_id, "cms", attr, page.soft_root, page.login_required, reverse_id=page.reverse_id)
return n
menu_pool.register_menu(CMSMenu, "main")
View
@@ -8,6 +8,7 @@
from cms.menu import CMSMenu
from menus.templatetags.menu_tags import show_menu, show_sub_menu,\
show_breadcrumb, language_chooser, page_language_url, show_menu_below_id
+from menus.menu_pool import menu_pool
class MenusTestCase(CMSTestCase):
@@ -152,12 +153,16 @@ def test_12_page_language_url(self):
self.assertEqual( url, "/%s%s" % (settings.LANGUAGES[0][0], self.page3.get_absolute_url()))
def test_13_show_menu_below_id(self):
+ menu_pool.clean_nodes()
self.create_some_nodes()
- self.page2.reverse_id = "hello"
- self.page2.save()
+ page2 = Page.objects.get(pk=self.page2.pk)
+ page2.reverse_id = "hello"
+ page2.save()
+ page2 = Page.objects.get(pk=self.page2.pk)
+ self.assertEqual(page2.reverse_id, "hello")
context = self.get_context(path=self.page5.get_absolute_url())
- nodes = show_menu_below_id(context, "hello")
+ nodes = show_menu_below_id(context, "hello")['children']
self.assertEqual(len(nodes), 1)
- self.assertEqual(nodes[0].get_absolute_url(), self.node3.get_absolute_url())
+ self.assertEqual(nodes[0].get_absolute_url(), self.page3.get_absolute_url())
View
@@ -41,10 +41,11 @@ class NavigationNode(object):
parent_id = None
parent_namespace = None
parent = None # do not touch
+ reverse_id = None
selected = False
- def __init__(self, title, url, namespace, id, parent_id=None, parent_namespace=None, attr=None, softroot=False, auth_required=False, required_group_id=None):
+ def __init__(self, title, url, namespace, id, parent_id=None, parent_namespace=None, attr=None, softroot=False, auth_required=False, required_group_id=None, reverse_id=None):
self.children = [] # do not touch
self.title = title
self.url = url
@@ -54,7 +55,8 @@ def __init__(self, title, url, namespace, id, parent_id=None, parent_namespace=N
self.parent_id = parent_id
self.parent_namespace = parent_namespace
self.auth_required = auth_required
- self.required_group_id = required_group_id
+ self.required_group_id = required_group_id
+ self.reverse_id = reverse_id
if attr:
self.attr = attr
View
@@ -26,6 +26,10 @@ def discover_menus(self):
inst = klass()
self.modifiers.append(inst)
self.discovered = True
+
+ def clean_nodes(self):
+ self.nodes = {}
+
def register_menu(self, menu, namespace):
from menus.base import Menu
@@ -73,7 +77,7 @@ def _build_nodes(self, request, site_id):
return self.nodes[lang][site_id]
def _apply_modifiers(self, nodes, request, namespace, root_id):
- self._mark_selected(request, nodes)
+ nodes = self._mark_selected(request, nodes)
for inst in self.modifiers:
inst.set_nodes(nodes)
inst.modify_all(request, nodes, namespace, root_id, False)
@@ -65,6 +65,17 @@ def show_menu(context, from_level=0, to_level=100, extra_inactive=0, extra_activ
else:
#new menu... get all the data so we can save a lot of queries
nodes = menu_pool.get_nodes(request, namespace, root_id)
+ if root_id: # find the root id and cut the nodes
+ new_nodes = []
+ for node in nodes:
+ if node.reverse_id == root_id:
+ new_nodes = node.children
+ for n in new_nodes:
+ n.parent = None
+ from_level += node.level + 1
+ to_level += node.level + 1
+ break
+ nodes = new_nodes
children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active)
context.update({'children':children,
'template':template,

0 comments on commit 27b30c2

Please sign in to comment.