63 return errorResponse(request, error, template, context) |
63 return errorResponse(request, error, template, context) |
64 |
64 |
65 return response_helpers.respond(request, template, context) |
65 return response_helpers.respond(request, template, context) |
66 |
66 |
67 |
67 |
|
68 def public(request, template, linkname, context): |
|
69 """A convenience wrapper around templateWithLinkName() using 'public.html'. |
|
70 |
|
71 Args: |
|
72 request, linkname, context: see templateWithLinkName() |
|
73 template: the "sibling" template (or a search list of such templates) |
|
74 from which to construct the public.html template name (or names) |
|
75 |
|
76 Returns: |
|
77 A subclass of django.http.HttpResponse containing the generated page. |
|
78 """ |
|
79 return simple.templateWithLinkName( |
|
80 request, linkname=linkname, context=context, |
|
81 template=template_helpers.makeSiblingTemplatesList( |
|
82 template, 'public.html')) |
|
83 |
|
84 |
68 DEF_ERROR_TMPL = 'soc/error.html' |
85 DEF_ERROR_TMPL = 'soc/error.html' |
69 |
86 |
70 def errorResponse(request, error, template, context): |
87 def errorResponse(request, error, template, context): |
71 """Displays an error page for an out_of_band.ErrorResponse exception. |
88 """Displays an error page for an out_of_band.ErrorResponse exception. |
72 |
89 |
91 context['error_status'] = error.response_args.get('status') |
108 context['error_status'] = error.response_args.get('status') |
92 context['error_message'] = error.message |
109 context['error_message'] = error.message |
93 |
110 |
94 return response_helpers.respond(request, error_templates, context=context, |
111 return response_helpers.respond(request, error_templates, context=context, |
95 response_args=error.response_args) |
112 response_args=error.response_args) |
|
113 |
|
114 |
|
115 DEF_LOGIN_TMPL = 'soc/login.html' |
|
116 DEF_LOGIN_MSG_FMT = 'Please <a href="%(sign_in)s">sign in</a> to continue.' |
|
117 |
|
118 def requestLogin(request, template, context, login_message_fmt=None): |
|
119 """Displays a login request page with custom message and login link. |
|
120 |
|
121 Args: |
|
122 request: the standard Django HTTP request object |
|
123 template: the "sibling" template (or a search list of such templates) |
|
124 from which to construct the login.html template name (or names) |
|
125 login_message_fmt: a custom message format string used to create a |
|
126 message displayed on the login page; the format string can contain |
|
127 named format specifiers for any of the keys in context, but should at |
|
128 least contain %(sign_in)s |
|
129 context: the context dict supplied to the template, which is modified |
|
130 (so supply a copy if such modification is not acceptable); |
|
131 login_message: the caller can completely construct the message supplied |
|
132 to the login template in lieu of using login_message_fmt |
|
133 """ |
|
134 context = response_helpers.getUniversalContext(request, context=context) |
|
135 |
|
136 # make a list of possible "sibling" templates, then append a default |
|
137 login_templates = template_helpers.makeSiblingTemplatesList(template, |
|
138 'login.html') |
|
139 login_templates.append(DEF_LOGIN_TMPL) |
|
140 |
|
141 if not context.get('login_message'): |
|
142 if not login_message_fmt: |
|
143 login_message_fmt = DEF_LOGIN_MSG_FMT |
|
144 context['login_message'] = login_message_fmt % context |
|
145 |
|
146 return response_helpers.respond(request, login_templates, context=context) |