author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Tue, 30 Sep 2008 12:59:59 +0000 | |
changeset 211 | ec26682053df |
parent 199 | 14ede160ef16 |
child 221 | 9cca97feadaa |
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 django.utils import datastructures |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
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
|
31 |
from soc.logic.site import id_user |
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 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
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
|
35 |
"""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
|
36 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
Args: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
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
|
39 |
(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
|
40 |
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
|
41 |
**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
|
42 |
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
|
43 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
if id is None: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
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
|
46 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
if not id: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
return [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
# user is logged out, so User top-level menu doubles as a sign-in link |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
50 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
'User (sign in)', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
value=users.create_login_url('/')), |
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 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
return [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
# user is logged in, so User top-level menu doubles as a sign-out link |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
'User (sign out)', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
value=users.create_logout_url('/'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
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
|
61 |
# edit existing (or create new) site-wide User profile |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
'Site-wide Profile', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
value='/user/profile'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
) |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
] |
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 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
|
72 |
"""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
|
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 |
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
|
76 |
(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
|
77 |
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
|
78 |
**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
|
79 |
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
|
80 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
84 |
if not is_admin: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
85 |
# 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
|
86 |
return None |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
87 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
return [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
# Site top-level menu doubles as link for editing site-wide settings |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
'Site', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
value='/site/home/edit', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
93 |
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
|
94 |
menu.MenuItem( |
199
14ede160ef16
Minor tweaks to Site menu item names to make them more descriptive.
Todd Larsen <tlarsen@google.com>
parents:
197
diff
changeset
|
95 |
'Search Site for a User', |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
96 |
value='/site/user/lookup'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
97 |
menu.MenuItem( |
199
14ede160ef16
Minor tweaks to Site menu item names to make them more descriptive.
Todd Larsen <tlarsen@google.com>
parents:
197
diff
changeset
|
98 |
'List Users of Site', |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
99 |
value='/site/user/list'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
100 |
menu.MenuItem( |
199
14ede160ef16
Minor tweaks to Site menu item names to make them more descriptive.
Todd Larsen <tlarsen@google.com>
parents:
197
diff
changeset
|
101 |
'Create a new Site User', |
197
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
value='/site/user/profile'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
) |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
105 |
), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
108 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
109 |
def buildProgramsSidebar(**unused): |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
110 |
"""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
|
111 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
112 |
Args: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
**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
|
114 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
115 |
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
|
116 |
Datastore. |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
117 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
118 |
return [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
119 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
120 |
'Google Summer of Code', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
121 |
value='/program/gsoc2009/home', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
122 |
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
|
123 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
124 |
'Community', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
125 |
value='/program/gsoc2009/community'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
126 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
127 |
'FAQs', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
128 |
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
|
129 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
130 |
'Terms of Service', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
131 |
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
|
132 |
] |
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 |
), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
135 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
136 |
'Google Highly Open Participation', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
137 |
value='/program/ghop2008/home', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
138 |
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
|
139 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
140 |
'Community', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
141 |
value='/program/ghop2008/community'), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
142 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
143 |
'FAQs', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
144 |
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
|
145 |
menu.MenuItem( |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
146 |
'Contest Rules', |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
147 |
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
|
148 |
] |
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 |
), |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
151 |
] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
152 |
|
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 |
DEF_SIDEBAR_BUILDERS = [ |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
155 |
buildUserSidebar, |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
156 |
buildSiteSidebar, |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
157 |
buildProgramsSidebar, |
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 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
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
|
161 |
"""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
|
162 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
163 |
Args: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
**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
|
168 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
Returns: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
170 |
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
|
171 |
""" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
172 |
menu_items = [] |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
173 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
174 |
# 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
|
175 |
for builder in builders: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
176 |
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
|
177 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
178 |
if built_items: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
179 |
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
|
180 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
# 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
|
182 |
# that it is "selected" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
183 |
if not path: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
184 |
# 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
|
185 |
# 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
|
186 |
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
|
187 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
188 |
if request: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
189 |
# 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
|
190 |
path = request.path |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
191 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
192 |
if path: |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
193 |
# TODO(tlarsen): scan through list and mark current request.path as "selected" |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
194 |
pass |
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
195 |
|
4cf7c0040f2e
Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
196 |
return menu.Menu(items=menu_items) |