author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Wed, 15 Oct 2008 20:24:02 +0000 | |
changeset 344 | d135c8c09967 |
parent 322 | 6641e941ef1e |
child 359 | 4308324241bc |
permissions | -rw-r--r-- |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
128
f6abf00efc62
Updated docs in response_helpers.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
119
diff
changeset
|
17 |
"""Helpers used to render response. |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
""" |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
21 |
'"Todd Larsen" <tlarsen@google.com>', |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
23 |
] |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
24 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
|
169
a9b3d6c9d4f9
Fix off-by-one corner case discovered during testing of /user/profile.
Todd Larsen <tlarsen@google.com>
parents:
167
diff
changeset
|
26 |
import logging |
167
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
27 |
|
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
28 |
from google.appengine.api import users |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
29 |
|
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
30 |
from django import http |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
31 |
from django.template import loader |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
32 |
|
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
33 |
from soc.logic import system |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
34 |
from soc.logic.site import id_user |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
35 |
from soc.logic.site import sidebar |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
36 |
from soc.views import helper |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
37 |
from soc.views.helper import html_menu |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
38 |
|
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
39 |
import soc.logic |
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
40 |
import soc.logic.models.user |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
41 |
import soc.views.helper.requests |
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
42 |
|
322
6641e941ef1e
Fixed imports sorting based on comments for r751.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
43 |
|
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
44 |
# DeadlineExceededError can live in two different places |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
45 |
try: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
46 |
# When deployed |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
47 |
from google.appengine.runtime import DeadlineExceededError |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
48 |
except ImportError: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
49 |
# In the development server |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
50 |
from google.appengine.runtime.apiproxy_errors import DeadlineExceededError |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
51 |
|
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
52 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
53 |
def respond(request, template, context=None, response_args=None): |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
54 |
"""Helper to render a response, passing standard stuff to the response. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
55 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
56 |
Args: |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
57 |
request: the Django HTTP request object |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
58 |
template: the template (or search list of templates) to render |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
59 |
context: the context supplied to the template (implements dict) |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
60 |
response_args: keyword arguments passed to http.HttpResponse() |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
61 |
(response_args['content'] is created with |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
62 |
render_to_string(template, dictionary=context) if it is not present) |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
63 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
64 |
Returns: |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
65 |
django.shortcuts.render_to_response(template, context) results |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
66 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
67 |
Raises: |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
68 |
Any exceptions that django.template.loader.render_to_string() or |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
69 |
django.http.HttpResponse() might raise. |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
70 |
""" |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
71 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
72 |
if not context: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
73 |
context = getUniversalContext(request) |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
74 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
75 |
if response_args is None: |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
76 |
response_args = {} |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
77 |
|
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
78 |
try: |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
79 |
response_args['content'] = response_args.get( |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
80 |
'content', loader.render_to_string(template, dictionary=context)) |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
81 |
return http.HttpResponse(**response_args) |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
82 |
except DeadlineExceededError: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
83 |
logging.exception('DeadlineExceededError') |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
84 |
return http.HttpResponse('DeadlineExceededError') |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
85 |
except MemoryError: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
86 |
logging.exception('MemoryError') |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
87 |
return http.HttpResponse('MemoryError') |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
88 |
except AssertionError: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
89 |
logging.exception('AssertionError') |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
90 |
return http.HttpResponse('AssertionError') |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
91 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
92 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
93 |
def getUniversalContext(request): |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
94 |
"""Constructs a template context dict will many common variables defined. |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
95 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
96 |
Args: |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
97 |
request: the Django HTTP request object |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
98 |
|
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
99 |
Returns: |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
100 |
a new context dict containing: |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
101 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
102 |
{ |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
103 |
'request': the Django HTTP request object passed in by the caller |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
104 |
'id': the logged-in Google Account if there is one |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
105 |
'user': the User entity corresponding to the Google Account in |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
106 |
context['id'] |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
107 |
'is_admin': True if users.is_current_user_admin() is True |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
108 |
'is_debug': True if system.isDebug() is True |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
109 |
'sign_in': a Google Account login URL |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
110 |
'sign_out': a Google Account logout URL |
200
8e3a18cead22
Replace mock-up of sidebar with first draft of dynamic sidebar functionality.
Todd Larsen <tlarsen@google.com>
parents:
190
diff
changeset
|
111 |
'sidebar_menu_html': an HTML string that renders the sidebar menu |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
112 |
} |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
113 |
""" |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
114 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
115 |
id = users.get_current_user() |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
116 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
117 |
context = {} |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
118 |
context['request'] = request |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
119 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
120 |
if id: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
121 |
context['id'] = id |
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
122 |
context['user'] = soc.logic.models.user.logic.getFromFields(email=id.email()) |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
123 |
context['is_admin'] = id_user.isIdDeveloper(id=id) |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
124 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
125 |
context['is_debug'] = system.isDebug() |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
126 |
context['sign_in'] = users.create_login_url(request.path) |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
127 |
context['sign_out'] = users.create_logout_url(request.path) |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
276
diff
changeset
|
128 |
context['sidebar_menu_html'] = str(html_menu.UlMenu( |
200
8e3a18cead22
Replace mock-up of sidebar with first draft of dynamic sidebar functionality.
Todd Larsen <tlarsen@google.com>
parents:
190
diff
changeset
|
129 |
sidebar.buildSidebar(**context))) |
8e3a18cead22
Replace mock-up of sidebar with first draft of dynamic sidebar functionality.
Todd Larsen <tlarsen@google.com>
parents:
190
diff
changeset
|
130 |
|
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
131 |
return context |
167
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
132 |
|
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
133 |
|
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
134 |
def redirectToChangedSuffix( |
179
4882d6c5630d
Add custom 404 error message with link to "Create a New User" which is displayed when linkname in User Profile Developer view URL (/site/user/profile/<linkname>) doesn't exist. Add default value (None) to new_suffix parameter of template_helpers replaceSuffix and redirectToChangedSuffix functions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
169
diff
changeset
|
135 |
request, old_suffix, new_suffix=None, params=None): |
167
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
136 |
"""Changes suffix of URL path and returns an HTTP redirect response. |
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
137 |
|
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
138 |
Args: |
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
139 |
request: the Django HTTP request object; redirect path is derived from |
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
140 |
request.path |
269
0f1acc4c3e1e
Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents:
267
diff
changeset
|
141 |
old_suffix, new_suffix, params: see helper.requests.replaceSuffix() |
167
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
142 |
|
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
143 |
Returns: |
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
144 |
a Django HTTP redirect response pointing to the altered path |
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
145 |
""" |
269
0f1acc4c3e1e
Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents:
267
diff
changeset
|
146 |
path = helper.requests.replaceSuffix(request.path, old_suffix, new_suffix, |
190
b1351bf81064
Move isReferrerSelf() and replaceSuffix() into new request_helpers.py module,
Todd Larsen <tlarsen@google.com>
parents:
179
diff
changeset
|
147 |
params=params) |
167
13e438623ded
Added replaceSuffix(), isReferrerSelf(), and redirectToChangedSuffix() to
Todd Larsen <tlarsen@google.com>
parents:
135
diff
changeset
|
148 |
return http.HttpResponseRedirect(path) |