Skip to content
Newer
Older
100644 69 lines (54 sloc) 1.8 KB
bc3158f @digi604 nav selection with apphooks works now
digi604 authored
1 from django.utils.translation import get_language
1b7eb7c @izimobil Fixed issue 398: menus crash when you have unicode characters at firs…
izimobil authored
2 from django.utils.encoding import smart_str
253adda @digi604 initial menu refactor
digi604 authored
3
589de2c @digi604 some start of the menu discover infrastructure
digi604 authored
4
5 class Menu(object):
bda49b2 @digi604 menu_levels working. nav-extenders correctly hiding if not assigned
digi604 authored
6 namespace = None
1b16cd4 @digi604 monster commit for menu refactor
digi604 authored
7
8 def __init__(self):
bda49b2 @digi604 menu_levels working. nav-extenders correctly hiding if not assigned
digi604 authored
9 if not self.namespace:
10 self.namespace = self.__class__.__name__
589de2c @digi604 some start of the menu discover infrastructure
digi604 authored
11
12 def get_nodes(self, request):
aeccf5b @digi604 sampleapp refactor for new menu structure
digi604 authored
13 """
14 should return a list of NavigationNode instances
15 """
589de2c @digi604 some start of the menu discover infrastructure
digi604 authored
16 raise NotImplementedError
17
18 class Modifier(object):
6e71206 @digi604 show menu working. marking of nodes working. modifiers working. cutle…
digi604 authored
19
1641218 @chrisglass Trivial changes:
chrisglass authored
20 def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
6e71206 @digi604 show menu working. marking of nodes working. modifiers working. cutle…
digi604 authored
21 pass
22
253adda @digi604 initial menu refactor
digi604 authored
23 class NavigationNode(object):
24 title = None
25 url = None
26 attr = {}
27 namespace = None
28 id = None
a36165f @digi604 some other menu refactoring... building up the api
digi604 authored
29 parent_id = None
30 parent_namespace = None
31 parent = None # do not touch
e0c3130 @stefanfoulis fixes #386: reverse_id does not work if the page has `in_navigation=F…
stefanfoulis authored
32 visible = True
a36165f @digi604 some other menu refactoring... building up the api
digi604 authored
33
e0c3130 @stefanfoulis fixes #386: reverse_id does not work if the page has `in_navigation=F…
stefanfoulis authored
34 def __init__(self, title, url, id, parent_id=None, parent_namespace=None, attr=None, visible=True):
6e71206 @digi604 show menu working. marking of nodes working. modifiers working. cutle…
digi604 authored
35 self.children = [] # do not touch
253adda @digi604 initial menu refactor
digi604 authored
36 self.title = title
bc3158f @digi604 nav selection with apphooks works now
digi604 authored
37 self.url = self._remove_current_root(url)
253adda @digi604 initial menu refactor
digi604 authored
38 self.id = id
a36165f @digi604 some other menu refactoring... building up the api
digi604 authored
39 self.parent_id = parent_id
40 self.parent_namespace = parent_namespace
e0c3130 @stefanfoulis fixes #386: reverse_id does not work if the page has `in_navigation=F…
stefanfoulis authored
41 self.visible = visible
253adda @digi604 initial menu refactor
digi604 authored
42 if attr:
43 self.attr = attr
6e71206 @digi604 show menu working. marking of nodes working. modifiers working. cutle…
digi604 authored
44
45 def __repr__(self):
1b7eb7c @izimobil Fixed issue 398: menus crash when you have unicode characters at firs…
izimobil authored
46 return "<Navigation Node: %s>" % smart_str(self.title)
253adda @digi604 initial menu refactor
digi604 authored
47
bc3158f @digi604 nav selection with apphooks works now
digi604 authored
48 def _remove_current_root(self, url):
49 current_root = "/%s/" % get_language()
50 if url[:len(current_root)] == current_root:
51 url = url[len(current_root) - 1:]
52 return url
53
253adda @digi604 initial menu refactor
digi604 authored
54 def get_menu_title(self):
55 return self.title
56
57 def get_absolute_url(self):
58 return self.url
59
60 def get_attribute(self, name):
61 return self.attr[name]
65331d8 @digi604 softroots working
digi604 authored
62
63 def get_descendants(self):
64 nodes = []
65 for node in self.children:
66 nodes.append(node)
67 nodes += node.get_descendants()
db11a23 fixed default menu modifier (#473)
Jonas Obrist authored
68 return nodes
Something went wrong with that request. Please try again.