author | Todd Larsen <tlarsen@google.com> |
Tue, 16 Sep 2008 17:05:07 +0000 | |
changeset 155 | 682c398c5aa7 |
parent 135 | a7ccde9d9eed |
child 167 | 13e438623ded |
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 |
|
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
|
26 |
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
|
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 django import http |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
29 |
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
|
30 |
|
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
|
31 |
# 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
|
32 |
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
|
33 |
# 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
|
34 |
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
|
35 |
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
|
36 |
# 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
|
37 |
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
|
38 |
|
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
39 |
from soc.logic import system |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
40 |
from soc.logic.site import id_user |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
41 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
42 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
43 |
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
|
44 |
"""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
|
45 |
|
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 |
Args: |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
(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
|
52 |
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
|
53 |
|
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 |
Returns: |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
55 |
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
|
56 |
|
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
|
57 |
Raises: |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
""" |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
61 |
context = getUniversalContext(request, context=context) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
62 |
|
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
63 |
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
|
64 |
response_args = {} |
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
65 |
|
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 |
try: |
119
50d8d58dcd7c
Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
116
diff
changeset
|
67 |
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
|
68 |
'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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
80 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
81 |
def getUniversalContext(request, context=None): |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
82 |
"""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
|
83 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
84 |
Args: |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
85 |
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
|
86 |
context: the template context dict to be updated in-place (pass in a copy |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
87 |
if the original must not be modified), or None if a new one is to be |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
88 |
created; any existing fields already present in the context dict passed |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
89 |
in by the caller are left unaltered |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
90 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
91 |
Returns: |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
92 |
updated template context dict supplied by the caller, or a new context |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
93 |
dict if the caller supplied None |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
94 |
|
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 |
'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
|
97 |
'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
|
98 |
'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
|
99 |
context['id'] |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
100 |
'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
|
101 |
'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
|
102 |
'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
|
103 |
'sign_out': a Google Account logout URL |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
104 |
} |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
105 |
""" |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
106 |
if context is None: |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
107 |
context = {} |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
108 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
109 |
# set some universal values if caller did not already set them |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
110 |
context['request'] = context.get('request', request) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
111 |
context['id'] = id_user.getIdIfMissing(context.get('id', None)) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
112 |
context['user'] = id_user.getUserIfMissing(context.get('user', None), |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
113 |
context['id']) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
114 |
context['is_admin'] = context.get( |
135
a7ccde9d9eed
Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
131
diff
changeset
|
115 |
'is_admin', id_user.isIdDeveloper(id=context['id'])) |
116
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
116 |
context['is_debug'] = context.get('is_debug', system.isDebug()) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
117 |
context['sign_in'] = context.get( |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
118 |
'sign_in', users.create_login_url(request.path)) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
119 |
context['sign_out'] = context.get( |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
120 |
'sign_out', users.create_logout_url(request.path)) |
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
121 |
|
68b5ce15fff9
Factor out a getUniversalContext() function so that views that do not call
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
122 |
return context |