Permalink
Browse files

some other menu refactoring... building up the api

  • Loading branch information...
digi604 committed Jan 8, 2010
1 parent d9ef610 commit a36165f369c4a273f52e4edc03e5e9b8715cb5e3
Showing with 62 additions and 31 deletions.
  1. +1 −1 example/settings.py
  2. +12 −5 menu/base.py
  3. +0 −25 menu/menu.py
  4. +49 −0 menu/modifiers.py
@@ -105,7 +105,7 @@
'cms',
'publisher',
'menu',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.file',
@@ -2,9 +2,6 @@
class Menu(object):
nodes = []
def add_nodes(self, nodes):
self.nodes.append(nodes)
def get_nodes(self, request):
raise NotImplementedError
@@ -18,17 +15,27 @@ def modify(self, request, nodes, namespace):
class NavigationNode(object):
title = None
url = None
auth_required = False
required_group_id = None
attr = {}
namespace = None
id = None
softroot = False
def __init__(self, title, url, namespace, id, attr=None, softroot=False):
parent_id = None
parent_namespace = None
parent = None # do not touch
childrens = [] # do not touch
def __init__(self, title, url, namespace, id, parent_id=None, parent_namespace=None, attr=None, softroot=False, auth_required=False, required_group_id=None):
self.title = title
self.url = url
self.id = id
self.softroot = softroot
self.namespace = namespace
self.parent_id = parent_id
self.parent_namespace = parent_namespace
self.auth_required = auth_required
self.required_group_id = required_group_id
if attr:
self.attr = attr

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,49 @@
from menu.base import Modifier
class Marker(Modifier):
"""
searches the current selected node and marks them.
current_node: selected = True
siblings: sibling = True
descendants: descendant = True
ancestors: ancestor = True
"""
def modify(self, request, node):
if node.get_absolute_url() == request.path:
node.selected = True
n = node
while n.parent:
n = n.parent
n.ancestor = True
if n.parent:
for n in n.parent.childrens:
if not n.selected:
n.sibling = True
self.mark_descendants(node.childrens)
return node
def mark_descendants(self, nodes):
for node in nodes:
node.descendant = True
self.mark_descendants(node.childrens)
class LoginRequired(Modifier):
"""
Remove nodes that are login required or require a group
"""
def modify(self, request, node):
good = False
if node.auth_required and request.user.is_authenticated():
good = True
if node.required_group_id and request.user.is_authenticated():
if not hasattr(request.user, "group_cache"):
request.user.group_cache = request.user.groups.all()
good = False
for group in request.user.group_cache:
if group.pk == node.required_group_id:
good = True
break
if good:
return node
return False

0 comments on commit a36165f

Please sign in to comment.