equal
deleted
inserted
replaced
22 ] |
22 ] |
23 |
23 |
24 |
24 |
25 from soc.views import out_of_band |
25 from soc.views import out_of_band |
26 |
26 |
27 import soc.cache.sidebar |
|
28 |
27 |
29 |
|
30 SIDEBAR = [] |
|
31 SIDEBAR_ACCESS_ARGS = ['SIDEBAR_CALLING'] |
28 SIDEBAR_ACCESS_ARGS = ['SIDEBAR_CALLING'] |
32 SIDEBAR_ACCESS_KWARGS = {'SIDEBAR_CALLING': True} |
29 SIDEBAR_ACCESS_KWARGS = {'SIDEBAR_CALLING': True} |
33 |
30 |
34 |
|
35 def addMenu(callback): |
|
36 """Adds a callback to the menu builder. |
|
37 |
|
38 The callback should return a list of menu's when called. |
|
39 """ |
|
40 global SIDEBAR |
|
41 SIDEBAR.append(callback) |
|
42 |
|
43 |
|
44 @soc.cache.sidebar.cache |
|
45 def getSidebar(id, user): |
|
46 """Constructs a sidebar for the current user. |
|
47 """ |
|
48 |
|
49 sidebar = [] |
|
50 |
|
51 for callback in SIDEBAR: |
|
52 menus = callback(id, user) |
|
53 |
|
54 for menu in (menus if menus else []): |
|
55 sidebar.append(menu) |
|
56 |
|
57 return sorted(sidebar, key=lambda x: x.get('group')) |
|
58 |
31 |
59 |
32 |
60 def getSidebarItems(params): |
33 def getSidebarItems(params): |
61 """Retrieves a list of sidebar entries for this view. |
34 """Retrieves a list of sidebar entries for this view. |
62 |
35 |