author | Sverre Rabbelier <srabbelier@gmail.com> |
Wed, 05 Nov 2008 23:32:59 +0000 | |
changeset 443 | 94568ac6e3e1 |
parent 425 | 95058c81a065 |
child 477 | 8a8b1bd035c4 |
permissions | -rw-r--r-- |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""Site-wide sidebar menu creation. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
__authors__ = [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
'"Todd Larsen" <tlarsen@google.com>', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
from google.appengine.api import users |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
from soc.logic import menu |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
from soc.logic.site import id_user |
283
52e5039ac0fc
Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents:
253
diff
changeset
|
30 |
from soc.logic.site import map |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
def buildUserSidebar(id=None, **ignored): |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
"""Returns a list of menu items for the User portion of the sidebar. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
Args: |
283
52e5039ac0fc
Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents:
253
diff
changeset
|
37 |
id: a Google Account (users.User) object; default is None, in which |
52e5039ac0fc
Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents:
253
diff
changeset
|
38 |
case users.get_current_user() is called |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
39 |
**ignored: other keyword arguments supplied to other sidebar builder |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
functions, but ignored by this one |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
if id is None: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
id = users.get_current_user() |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
if not id: |
425
95058c81a065
Change Site and User sub-menus so that the "header" entry for those sub-menus
Todd Larsen <tlarsen@google.com>
parents:
389
diff
changeset
|
46 |
return [map.user_signin_sub_menu.makeMenuItem()] |
283
52e5039ac0fc
Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents:
253
diff
changeset
|
47 |
|
425
95058c81a065
Change Site and User sub-menus so that the "header" entry for those sub-menus
Todd Larsen <tlarsen@google.com>
parents:
389
diff
changeset
|
48 |
return [map.user_signout_sub_menu.makeMenuItem()] |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
50 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
def buildSiteSidebar(is_admin=None, **ignored): |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
"""Returns a list of menu items for the Developer portion of the sidebar. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
Args: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
is_admin: Boolean indicating that current user is a "Developer" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
(site super-user); default is None, in which case |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
id_user.isIdDeveloper() is called |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
**ignored: other keyword arguments supplied to other sidebar builder |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
functions, but ignored by this one |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
if is_admin is None: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
is_admin = id_user.isIdDeveloper() |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
if not is_admin: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
# user is either not logged in or not a "Developer", so return no menu |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
return None |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
|
425
95058c81a065
Change Site and User sub-menus so that the "header" entry for those sub-menus
Todd Larsen <tlarsen@google.com>
parents:
389
diff
changeset
|
68 |
return [map.site_sub_menu.makeMenuItem()] |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
def buildProgramsSidebar(**unused): |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
"""Mock-up for Programs section of sidebar menu. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
Args: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
**unused: all keyword arguments are currently unused in this mock-up |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
76 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
TODO: actually implement this once Program entities are present in the |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
78 |
Datastore. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
79 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
80 |
return [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
81 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
82 |
'Google Summer of Code', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
83 |
value='/program/gsoc2009/home', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
84 |
sub_menu=menu.Menu(items=[ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
85 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
86 |
'Community', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
87 |
value='/program/gsoc2009/community'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
'FAQs', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
value='/program/gsoc2009/docs/faqs'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
'Terms of Service', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
93 |
value='/program/gsoc2009/docs/tos'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
) |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
96 |
), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
97 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
98 |
'Google Highly Open Participation', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
99 |
value='/program/ghop2008/home', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
100 |
sub_menu=menu.Menu(items=[ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
101 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
'Community', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
value='/program/ghop2008/community'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
105 |
'FAQs', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
value='/program/ghop2008/docs/faqs'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
108 |
'Contest Rules', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
109 |
value='/program/ghop2008/docs/rules'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
110 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
111 |
) |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
112 |
), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
114 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
115 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
116 |
DEF_SIDEBAR_BUILDERS = [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
117 |
buildUserSidebar, |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
118 |
buildSiteSidebar, |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
119 |
buildProgramsSidebar, |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
120 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
121 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
122 |
def buildSidebar(path=None, builders=DEF_SIDEBAR_BUILDERS, **builder_args): |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
123 |
"""Calls all sidebar builders to construct the sidebar menu. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
124 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
125 |
Args: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
126 |
builders: list of functions that take context as a single |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
127 |
argument; default is the list of sidebar builder functions present |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
128 |
in soc.logic.site.sidebar |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
129 |
**builder_args: keyword arguments passed to each sidebar builder function |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
130 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
131 |
Returns: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
132 |
an soc.logic.menu.Menu object containing the sidebar menu items |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
133 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
134 |
menu_items = [] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
135 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
136 |
# call each of the sidebar builders and append any menu items they create |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
137 |
for builder in builders: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
138 |
built_items = builder(**builder_args) |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
139 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
140 |
if built_items: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
141 |
menu_items.extend(built_items) |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
142 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
143 |
# try to determine which of the menu items is the current path, to indicate |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
144 |
# that it is "selected" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
145 |
if not path: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
146 |
# path argument not supplied, so see if an HTTP request object was |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
147 |
# supplied in the builder_args |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
148 |
request = builder_args.get('request') |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
149 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
150 |
if request: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
151 |
# there is an HTTP request object, so use the path stored in it |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
152 |
path = request.path |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
153 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
154 |
if path: |
389
9b873166d7d5
Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
348
diff
changeset
|
155 |
# TODO(tlarsen): scan through list and mark current request.path |
9b873166d7d5
Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
348
diff
changeset
|
156 |
# as "selected" |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
157 |
pass |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
158 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
159 |
return menu.Menu(items=menu_items) |