Skip to content
Newer
Older
100644 66 lines (51 sloc) 1.83 KB
9966d47 @chrisglass Source encoding changes for menus app
chrisglass authored
1 # -*- coding: utf-8 -*-
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 firs…
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. cutle…
digi604 authored
20
1641218 @chrisglass Trivial changes:
chrisglass authored
21 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
22 pass
23
253adda @digi604 initial menu refactor
digi604 authored
24 class NavigationNode(object):
a36165f @digi604 some other menu refactoring... building up the api
digi604 authored
25
e0c3130 @stefanfoulis fixes #386: reverse_id does not work if the page has `in_navigation=F…
stefanfoulis authored
26 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
27 self.children = [] # do not touch
1104e5c @chrisglass Removed class attributes and made them instance-level instead in Navi…
chrisglass authored
28 self.parent = None # do not touch, code depends on this
29 self.namespace = None # TODO: Assert why we need this and above
253adda @digi604 initial menu refactor
digi604 authored
30 self.title = title
6133635 @digi604 base language chooser working
digi604 authored
31 self.url = url
253adda @digi604 initial menu refactor
digi604 authored
32 self.id = id
a36165f @digi604 some other menu refactoring... building up the api
digi604 authored
33 self.parent_id = parent_id
34 self.parent_namespace = parent_namespace
e0c3130 @stefanfoulis fixes #386: reverse_id does not work if the page has `in_navigation=F…
stefanfoulis authored
35 self.visible = visible
1104e5c @chrisglass Removed class attributes and made them instance-level instead in Navi…
chrisglass authored
36
253adda @digi604 initial menu refactor
digi604 authored
37 if attr:
38 self.attr = attr
1104e5c @chrisglass Removed class attributes and made them instance-level instead in Navi…
chrisglass authored
39 else:
40 self.attr = {} # To avoid declaring a dict in defaults...
6e71206 @digi604 show menu working. marking of nodes working. modifiers working. cutle…
digi604 authored
41
42 def __repr__(self):
1b7eb7c @izimobil Fixed issue 398: menus crash when you have unicode characters at firs…
izimobil authored
43 return "<Navigation Node: %s>" % smart_str(self.title)
253adda @digi604 initial menu refactor
digi604 authored
44
45 def get_menu_title(self):
46 return self.title
47
48 def get_absolute_url(self):
49 return self.url
50
51 def get_attribute(self, name):
52 return self.attr[name]
65331d8 @digi604 softroots working
digi604 authored
53
54 def get_descendants(self):
55 nodes = []
56 for node in self.children:
57 nodes.append(node)
58 nodes += node.get_descendants()
db11a23 fixed default menu modifier (#473)
Jonas Obrist authored
59 return nodes
9d0323a Fixed issue 662, no idea if this is a valid fix but wtf are soft root…
Jonas Obrist authored
60
61 def get_ancestors(self):
62 nodes = []
1104e5c @chrisglass Removed class attributes and made them instance-level instead in Navi…
chrisglass authored
63 if getattr(self, 'parent', None):
9d0323a Fixed issue 662, no idea if this is a valid fix but wtf are soft root…
Jonas Obrist authored
64 nodes.append(self.parent)
65 nodes += self.parent.get_ancestors()
66 return nodes
Something went wrong with that request. Please try again.