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.
http://code.google.com/p/soc/source/detail?r=817
Patch by: Pawel Solyga
Review by: to-be-reviewed
--- a/app/soc/views/docs/show.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/docs/show.py Thu Oct 16 17:34:10 2008 +0000
@@ -77,7 +77,7 @@
link_name=link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when Document path doesn't exist in Datastore
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
doc.content = helper.templates.unescape(doc.content)
context['document'] = doc
--- a/app/soc/views/helper/access.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/helper/access.py Thu Oct 16 17:34:10 2008 +0000
@@ -74,7 +74,7 @@
if users.get_current_user():
return
- login_response = requestLogin(request, DEF_LOGIN_TMPL,
+ login_response = requestLogin(request, None, DEF_LOGIN_TMPL,
login_message_fmt=DEF_LOGIN_MSG_FMT)
raise soc.views.out_of_band.AccessViolationResponse(login_response)
@@ -103,7 +103,7 @@
if user:
return
- login_response = requestLogin(request, DEF_LOGIN_TMPL,
+ login_response = requestLogin(request, None, DEF_LOGIN_TMPL,
login_message_fmt=DEF_NO_USER_LOGIN_MSG_FMT)
raise soc.views.out_of_band.AccessViolationResponse(login_response)
@@ -135,7 +135,7 @@
'role' : 'a site developer ',
}
- login_response = requestLogin(request, DEF_LOGIN_TMPL,
+ login_response = requestLogin(request, None, DEF_LOGIN_TMPL,
login_message_fmt=login_message_fmt)
raise soc.views.out_of_band.AccessViolationResponse(login_response)
@@ -168,7 +168,7 @@
'role' : 'a host for this program',
}
- login_response = requestLogin(request, DEF_LOGIN_TMPL,
+ login_response = requestLogin(request, None, DEF_LOGIN_TMPL,
login_message_fmt=login_message_fmt)
raise soc.views.out_of_band.AccessViolationResponse(login_response)
--- a/app/soc/views/simple.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/simple.py Thu Oct 16 17:34:10 2008 +0000
@@ -34,12 +34,16 @@
import soc.views.helper.templates
-def public(request, template='soc/base.html', link_name=None,
- context=None, page=None):
+DEF_PUBLIC_TMPL = 'soc/base.html'
+
+def public(request, page=None, template=DEF_PUBLIC_TMPL, link_name=None,
+ context=None):
"""A simple template view that expects a link_name extracted from the URL.
Args:
request: the standard Django HTTP request object
+ page: a soc.logic.site.page.Page object which is abstraction that combines
+ a Django view with sidebar menu info
template: the template to use for rendering the view (or a search list
of templates)
link_name: a site-unique "link_name" (usually extracted from the URL)
@@ -48,8 +52,7 @@
link_name: the link_name parameter is added to the context
link_name_user: if the link_name exists for a User, that User
is added to the context
- page: a soc.logic.site.page.Page object which is abstraction that combines
- a Django view with sidebar menu info
+
Returns:
A subclass of django.http.HttpResponse containing the generated page.
@@ -64,7 +67,7 @@
if link_name:
user = id_user.getUserFromLinkNameOr404(link_name)
except out_of_band.ErrorResponse, error:
- return errorResponse(request, error, template, context, page)
+ return errorResponse(request, page, error, template, context)
context['link_name'] = link_name
context['link_name_user'] = user
@@ -74,12 +77,13 @@
DEF_ERROR_TMPL = 'soc/error.html'
-
-def errorResponse(request, error, template, context, page=None):
+def errorResponse(request, page, error, template, context):
"""Displays an error page for an out_of_band.ErrorResponse exception.
Args:
request: the standard Django HTTP request object
+ page: a soc.logic.site.page.Page object which is abstraction that combines
+ a Django view with sidebar menu info
error: an out_of_band.ErrorResponse exception
template: the "sibling" template (or a search list of such templates)
from which to construct the error.html template name (or names)
@@ -88,8 +92,7 @@
error_message: the error message string from error.message
error_status: error.response_args['status'], or None if a status code
was not supplied to the ErrorResponse
- page: a soc.logic.site.page.Page object which is abstraction that combines
- a Django view with sidebar menu info
+
"""
if not context:
@@ -110,12 +113,13 @@
DEF_LOGIN_MSG_FMT = ugettext_lazy(
'Please <a href="%(sign_in)s">sign in</a> to continue.')
-def requestLogin(request, template, context=None, login_message_fmt=None,
- page=None):
+def requestLogin(request, page, template, context=None, login_message_fmt=None):
"""Displays a login request page with custom message and login link.
Args:
request: the standard Django HTTP request object
+ page: a soc.logic.site.page.Page object which is abstraction that combines
+ a Django view with sidebar menu info
template: the "sibling" template (or a search list of such templates)
from which to construct the login.html template name (or names)
login_message_fmt: a custom message format string used to create a
@@ -126,8 +130,7 @@
(so supply a copy if such modification is not acceptable)
login_message: the caller can completely construct the message supplied
to the login template in lieu of using login_message_fmt
- page: a soc.logic.site.page.Page object which is abstraction that combines
- a Django view with sidebar menu info
+
"""
if not context:
--- a/app/soc/views/site/docs/edit.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/site/docs/edit.py Thu Oct 16 17:34:10 2008 +0000
@@ -206,7 +206,7 @@
except out_of_band.ErrorResponse, error:
# show custom 404 page when path doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_DOC_MSG
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
if request.method == 'POST':
form = EditForm(request.POST)
@@ -310,7 +310,7 @@
except out_of_band.ErrorResponse, error:
# show custom 404 page when path doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_DOC_MSG
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
if existing_doc:
document.logic.delete(existing_doc)
--- a/app/soc/views/site/sponsor/profile.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/site/sponsor/profile.py Thu Oct 16 17:34:10 2008 +0000
@@ -123,7 +123,7 @@
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
if request.method == 'POST':
if existing_sponsor:
@@ -139,7 +139,7 @@
if sponsor_form.cleaned_data.get('link_name') != link_name:
msg = DEF_SPONSOR_NO_LINKNAME_CHANGE_MSG
error = out_of_band.ErrorResponse(msg)
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
fields = {}
@@ -239,7 +239,7 @@
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
if existing_sponsor:
# TODO(pawel.solyga): Create specific delete method for Sponsor model
--- a/app/soc/views/site/user/profile.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/site/user/profile.py Thu Oct 16 17:34:10 2008 +0000
@@ -283,7 +283,7 @@
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_USER_MSG
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
if request.method == 'POST':
--- a/app/soc/views/sponsor/profile.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/sponsor/profile.py Thu Oct 16 17:34:10 2008 +0000
@@ -54,7 +54,7 @@
link_name_sponsor = soc.logic.models.sponsor.logic.getIfFields(link_name=link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
link_name_sponsor.description = \
helper.templates.unescape(link_name_sponsor.description)
--- a/app/soc/views/user/profile.py Thu Oct 16 17:30:58 2008 +0000
+++ b/app/soc/views/user/profile.py Thu Oct 16 17:34:10 2008 +0000
@@ -104,7 +104,7 @@
if (not id) and (not link_name):
# not logged in, and no link name, so request that the user sign in
- return simple.requestLogin(request, template, context, page=page,
+ return simple.requestLogin(request, page, template, context,
# TODO(tlarsen): /user/profile could be a link to a help page instead
login_message_fmt='To create a new'
' <a href="/user/profile">User Profile</a>'
@@ -113,7 +113,8 @@
if (not id) and link_name:
# not logged in, so show read-only public profile for link_name user
- return simple.public(request, template, link_name, context, page)
+ return simple.public(request, page=page, template=template,
+ link_name=link_name, context=context)
link_name_user = None
@@ -123,13 +124,14 @@
link_name_user = id_user.getUserFromLinkNameOr404(link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
- return simple.errorResponse(request, error, template, context, page)
+ return simple.errorResponse(request, page, error, template, context)
# link_name_user will be None here if link name was already None...
if link_name_user and (link_name_user.id != id):
# link_name_user exists but is not the currently logged in Google Account,
# so show public view for that (other) User entity
- return simple.public(request, template, link_name, context, page)
+ return simple.public(request, page=page, template=template,
+ link_name=link_name, context=context)
if request.method == 'POST':
form = UserForm(request.POST)