Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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