author | Todd Larsen <tlarsen@google.com> |
Sat, 18 Oct 2008 05:30:57 +0000 | |
changeset 380 | de296c7e3066 |
parent 374 | 9363b9dc2983 |
child 481 | 94834a1e6c01 |
permissions | -rw-r--r-- |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""Simple views that depend entirely on the template and context. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
""" |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
'"Todd Larsen" <tlarsen@google.com>', |
141
e120c24b89e2
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
139
diff
changeset
|
22 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
] |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
|
139
93a9a22a4c38
Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents:
125
diff
changeset
|
26 |
from django.utils.translation import ugettext_lazy |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
from soc.logic import out_of_band |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
from soc.logic.site import id_user |
270
7dd6d8347b56
Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
30 |
from soc.views import helper |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
31 |
from soc.views.helper import decorators |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
299
diff
changeset
|
32 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
270
diff
changeset
|
33 |
import soc.views.helper.responses |
270
7dd6d8347b56
Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
34 |
import soc.views.helper.templates |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
|
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
37 |
DEF_PUBLIC_TMPL = 'soc/base.html' |
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
38 |
|
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
39 |
@decorators.view |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
40 |
def public(request, page=None, template=DEF_PUBLIC_TMPL, link_name=None, |
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
41 |
context=None): |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
42 |
"""A simple template view that expects a link_name extracted from the URL. |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
Args: |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
request: the standard Django HTTP request object |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
46 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
47 |
a Django view with sidebar menu info |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
template: the template to use for rendering the view (or a search list |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
of templates) |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
50 |
link_name: a site-unique "link_name" (usually extracted from the URL) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
context: the context dict supplied to the template, which is modified |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
52 |
(so supply a copy if such modification is not acceptable) |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
53 |
link_name: the link_name parameter is added to the context |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
54 |
link_name_user: if the link_name exists for a User, that User |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
55 |
is added to the context |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
56 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
Returns: |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
A subclass of django.http.HttpResponse containing the generated page. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
""" |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
61 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
62 |
template = helper.templates.makeSiblingTemplatesList(template, 'public.html') |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
63 |
|
374
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
64 |
# TODO(tlarsen): fix getUniversalContext() so that it is back to being a |
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
65 |
# dict merge of missing defaults (as discussed at length in recent code |
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
66 |
# reviews) |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
67 |
if not context: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
68 |
context = helper.responses.getUniversalContext(request) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
|
374
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
70 |
context['page'] = page |
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
71 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
try: |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
73 |
if link_name: |
355
9b3f26057f74
Change name of getUserFromLinkNameOrDie function to getUserFromLinkNameOr404 and apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
74 |
user = id_user.getUserFromLinkNameOr404(link_name) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
except out_of_band.ErrorResponse, error: |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
76 |
return errorResponse(request, page, error, template, context) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
78 |
context['link_name'] = link_name |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
79 |
context['link_name_user'] = user |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
80 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
270
diff
changeset
|
81 |
return helper.responses.respond(request, template, context) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
82 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
83 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
84 |
DEF_ERROR_TMPL = 'soc/error.html' |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
85 |
|
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
86 |
def errorResponse(request, page, error, template, context): |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
87 |
"""Displays an error page for an out_of_band.ErrorResponse exception. |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
Args: |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
request: the standard Django HTTP request object |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
91 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
92 |
a Django view with sidebar menu info |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
93 |
error: an out_of_band.ErrorResponse exception |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
template: the "sibling" template (or a search list of such templates) |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
from which to construct the error.html template name (or names) |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
96 |
context: the context dict supplied to the template, which is modified |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
97 |
(so supply a copy if such modification is not acceptable) |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
98 |
error_message: the error message string from error.message |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
99 |
error_status: error.response_args['status'], or None if a status code |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
100 |
was not supplied to the ErrorResponse |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
101 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
""" |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
103 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
104 |
if not context: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
105 |
context = helper.responses.getUniversalContext(request) |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
106 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
# make a list of possible "sibling" templates, then append a default |
270
7dd6d8347b56
Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
108 |
error_templates = helper.templates.makeSiblingTemplatesList( |
125
155f43a0fa68
An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents:
123
diff
changeset
|
109 |
template, 'error.html', default_template=DEF_ERROR_TMPL) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
110 |
|
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
111 |
context['error_status'] = error.response_args.get('status') |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
112 |
context['error_message'] = error.message |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
270
diff
changeset
|
114 |
return helper.responses.respond(request, error_templates, context=context, |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
115 |
response_args=error.response_args) |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
116 |
|
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
117 |
|
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
118 |
DEF_LOGIN_TMPL = 'soc/login.html' |
139
93a9a22a4c38
Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents:
125
diff
changeset
|
119 |
DEF_LOGIN_MSG_FMT = ugettext_lazy( |
93a9a22a4c38
Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents:
125
diff
changeset
|
120 |
'Please <a href="%(sign_in)s">sign in</a> to continue.') |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
121 |
|
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
122 |
def requestLogin(request, page, template, context=None, login_message_fmt=None): |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
123 |
"""Displays a login request page with custom message and login link. |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
124 |
|
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
125 |
Args: |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
126 |
request: the standard Django HTTP request object |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
127 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
128 |
a Django view with sidebar menu info |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
129 |
template: the "sibling" template (or a search list of such templates) |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
130 |
from which to construct the login.html template name (or names) |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
131 |
login_message_fmt: a custom message format string used to create a |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
132 |
message displayed on the login page; the format string can contain |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
133 |
named format specifiers for any of the keys in context, but should at |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
134 |
least contain %(sign_in)s |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
135 |
context: the context dict supplied to the template, which is modified |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
136 |
(so supply a copy if such modification is not acceptable) |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
137 |
login_message: the caller can completely construct the message supplied |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
355
diff
changeset
|
138 |
to the login template in lieu of using login_message_fmt |
361
465e4df617de
Make page argument required for errorResponse and requestLogin functions in simple.py and update affected files. Some keyword argument changes to in user/profile.py. All the changes are based on comments to r817.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
139 |
|
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
140 |
""" |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
141 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
142 |
if not context: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
295
diff
changeset
|
143 |
context = helper.responses.getUniversalContext(request) |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
144 |
|
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
145 |
# make a list of possible "sibling" templates, then append a default |
270
7dd6d8347b56
Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
146 |
login_templates = helper.templates.makeSiblingTemplatesList( |
125
155f43a0fa68
An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents:
123
diff
changeset
|
147 |
template, 'login.html', default_template=DEF_LOGIN_TMPL) |
122
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
148 |
|
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
149 |
if not context.get('login_message'): |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
150 |
if not login_message_fmt: |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
151 |
login_message_fmt = DEF_LOGIN_MSG_FMT |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
152 |
context['login_message'] = login_message_fmt % context |
95d0d954fe0b
Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents:
119
diff
changeset
|
153 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
270
diff
changeset
|
154 |
return helper.responses.respond(request, login_templates, context=context) |
139
93a9a22a4c38
Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents:
125
diff
changeset
|
155 |