|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2008 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 """Site map information, used to generate sidebar menus, urlpatterns, etc. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Todd Larsen" <tlarsen@google.com>', |
|
22 ] |
|
23 |
|
24 |
|
25 import copy |
|
26 import re |
|
27 |
|
28 from google.appengine.api import users |
|
29 |
|
30 from django.conf.urls import defaults |
|
31 from django.utils import datastructures |
|
32 |
|
33 from soc.logic import path_linkname |
|
34 from soc.logic.site import page |
|
35 |
|
36 |
|
37 # Home Page view |
|
38 home = page.Page( |
|
39 page.Url( |
|
40 r'^$', |
|
41 'soc.views.site.home.public'), |
|
42 'Google Open Source Programs', |
|
43 # it should be obvious that every page comes from the home page |
|
44 in_breadcrumb=False) |
|
45 |
|
46 # User authentication view placeholders |
|
47 # (these are not real Django views, but need to appear in menus, etc.) |
|
48 user_signin = page.Page( |
|
49 page.Url( |
|
50 # not a real Django URL regex, just a unique placeholder |
|
51 users.create_login_url('/'), |
|
52 # no view, since App Engine handles this page |
|
53 # (this page will not be placed in urlpatterns) |
|
54 None, |
|
55 # name is alternate string for view when it is not unique |
|
56 name='user-sign-in'), |
|
57 'User (sign in)', |
|
58 link_url=users.create_login_url('/'), |
|
59 parent=home) |
|
60 |
|
61 user_signout = page.Page( |
|
62 page.Url( |
|
63 # not a real Django URL regex, just a unique placeholder |
|
64 users.create_logout_url('/'), |
|
65 # no view, since App Engine handles this page |
|
66 # (this page will not be placed in urlpatterns) |
|
67 None, |
|
68 # name is alternate string for view when it is not unique |
|
69 name='user-sign-out'), |
|
70 'User (sign out)', |
|
71 link_url=users.create_logout_url('/'), |
|
72 parent=home) |
|
73 |
|
74 # User Profile views |
|
75 user_create = page.Page( |
|
76 page.Url( |
|
77 r'^user/profile$', |
|
78 'soc.views.user.profile.create'), |
|
79 'User: Create a New Profile', |
|
80 short_name='Site-wide User Profile', |
|
81 parent=user_signout) |
|
82 |
|
83 user_edit = page.Page( |
|
84 page.Url( |
|
85 r'^user/profile/%s$' % path_linkname.LINKNAME_ARG_PATTERN, |
|
86 'soc.views.user.profile.edit'), |
|
87 'User: Modify Existing User Profile', |
|
88 parent=user_signout) |
|
89 |
|
90 # Site Home Page views |
|
91 site_home = page.Page( |
|
92 page.Url( |
|
93 r'^site/home$', |
|
94 'soc.views.site.home.public'), |
|
95 'Google Open Source Programs', |
|
96 # it should be obvious that every page comes from the home page |
|
97 in_breadcrumb=False) |
|
98 |
|
99 site_home_edit = page.Page( |
|
100 page.Url( |
|
101 r'^site/home/edit$', |
|
102 'soc.views.site.home.edit'), |
|
103 'Site: Settings', |
|
104 short_name='Site Settings', |
|
105 parent=home) |
|
106 |
|
107 # Site User Profile views |
|
108 site_user_lookup = page.Page( |
|
109 page.Url( |
|
110 r'^site/user/lookup$', |
|
111 'soc.views.site.user.profile.lookup'), |
|
112 'Site: Look Up an Existing User', |
|
113 short_name='Look Up Site User', |
|
114 parent=site_home_edit) |
|
115 |
|
116 site_user_create = page.Page( |
|
117 page.Url( |
|
118 r'^site/user/profile$', |
|
119 'soc.views.site.user.profile.create'), |
|
120 'Site: Create New User Profile', |
|
121 short_name='Create Site User', |
|
122 parent=site_home_edit) |
|
123 |
|
124 site_user_edit = page.Page( |
|
125 page.Url( |
|
126 r'^site/user/profile/%s$' % path_linkname.LINKNAME_ARG_PATTERN, |
|
127 'soc.views.site.user.profile.edit'), |
|
128 'Site: Modify Existing User Profile', |
|
129 short_name='Modify Site User', |
|
130 parent=site_home_edit) |
|
131 |
|
132 site_user_list = page.Page( |
|
133 page.Url( |
|
134 r'^site/user/list$', |
|
135 'soc.views.site.user.list.all'), |
|
136 'Site: List of Users', |
|
137 short_name='List Site Users', |
|
138 parent=site_home_edit) |
|
139 |
|
140 # Document views |
|
141 docs_show = page.Page( |
|
142 page.Url( |
|
143 r'^docs/show/%s$' % path_linkname.PATH_LINKNAME_ARGS_PATTERN, |
|
144 'soc.views.docs.show.public'), |
|
145 'Show Document', |
|
146 parent=home) |
|
147 |
|
148 # Site Document views |
|
149 site_docs_create = page.Page( |
|
150 page.Url( |
|
151 r'^site/docs/edit$', |
|
152 'soc.views.site.docs.edit.create'), |
|
153 'Site: Create New Document', |
|
154 'Create new Site Document', |
|
155 parent=site_home_edit) |
|
156 |
|
157 site_docs_edit = page.Page( |
|
158 page.Url( |
|
159 r'^site/docs/edit/%s$' % path_linkname.PATH_LINKNAME_ARGS_PATTERN, |
|
160 'soc.views.site.docs.edit.edit'), |
|
161 'Site: Modify Existing Document', |
|
162 short_name='Modify Site Document', |
|
163 parent=site_home_edit) |
|
164 |
|
165 site_docs_list = page.Page( |
|
166 page.Url( |
|
167 r'^site/docs/list$', |
|
168 'soc.views.site.docs.list.all'), |
|
169 'Site: List of Documents', |
|
170 short_name='List Site Documents', |
|
171 parent=site_home_edit) |
|
172 |
|
173 # Sponsor Group public view |
|
174 sponsor_profile = page.Page( |
|
175 page.Url( |
|
176 r'^sponsor/profile/%s' % path_linkname.LINKNAME_ARG_PATTERN, |
|
177 'soc.views.sponsor.profile.public'), |
|
178 'Public Profile', |
|
179 parent=home) |
|
180 |
|
181 # Sponsor Group Site views |
|
182 site_sponsor_create = page.Page( |
|
183 page.Url( |
|
184 r'^site/sponsor/profile$', |
|
185 'soc.views.site.sponsor.profile.create'), |
|
186 'Site: Create New Sponsor', |
|
187 short_name='Create New Site Sponsor', |
|
188 parent=site_home_edit) |
|
189 |
|
190 site_sponsor_edit = page.Page( |
|
191 page.Url( |
|
192 r'^site/sponsor/profile/%s' % path_linkname.LINKNAME_ARG_PATTERN, |
|
193 'soc.views.site.sponsor.profile.edit'), |
|
194 'Site: Modify Existing Sponsor', |
|
195 short_name='Modify Site Sponsor', |
|
196 parent=site_home_edit) |
|
197 |
|
198 site_sponsor_list = page.Page( |
|
199 page.Url( |
|
200 r'^site/sponsor/list$', |
|
201 'soc.views.site.sponsor.list.all'), |
|
202 'Site: List of Sponsors', |
|
203 short_name='List Site Sponsors', |
|
204 parent=site_home_edit) |
|
205 |
|
206 |
|
207 # these are not really used... |
|
208 # (r'^org/profile/(?P<program>ghop[_0-9a-z]+)/(?P<linkname>[_0-9a-z]+)/$', |
|
209 # 'soc.views.person.profile.edit', |
|
210 # {'template': 'ghop/person/profile/edit.html'}), |
|
211 # (r'^org/profile/(?P<program>[_0-9a-z]+)/(?P<linkname>[_0-9a-z]+)/$', |
|
212 # 'soc.views.person.profile.edit'), |
|
213 |
|
214 |
|
215 ROOT_PAGES = [ |
|
216 # /, first level of the sidebar menu, excluded from breadcrumbs |
|
217 home, |
|
218 |
|
219 # alternate view of /, no menu presence |
|
220 site_home, |
|
221 ] |
|
222 |
|
223 |
|
224 def getDjangoUrlPatterns(pages=ROOT_PAGES): |
|
225 """Returns Django urlpatterns derived from the site map Pages. |
|
226 |
|
227 Args: |
|
228 pages: a list of page.Page objects from which to generate urlpatterns |
|
229 (from them and from their child Pages); default is ROOT_PAGES |
|
230 |
|
231 Raises: |
|
232 KeyError if more than one Page has the same urlpattern. |
|
233 |
|
234 TODO(tlarsen): this probably does not work correctly, currently, since |
|
235 page.Page.makeDjangoUrls() returns a list, and this routine is |
|
236 combining lists from potentially multiple page hierarchies. Each list |
|
237 might have a urlpattern that the other contains, but this won't be |
|
238 detected by the current code (will Django catch this?). This really |
|
239 needs to be detected earlier via a global Page dictionary. |
|
240 """ |
|
241 urlpatterns = [''] |
|
242 |
|
243 for page in pages: |
|
244 urlpatterns.extend(page.makeDjangoUrls()) |
|
245 |
|
246 return defaults.patterns(*urlpatterns) |