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.
authorPawel Solyga <Pawel.Solyga@gmail.com>
Thu, 16 Oct 2008 15:22:41 +0000
changeset 358 843d83b87282
parent 357 9bd78a5073c2
child 359 4308324241bc
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. Patch by: Pawel Solyga Review by: to-be-reviewed
app/soc/views/docs/show.py
app/soc/views/person/profile.py
app/soc/views/simple.py
app/soc/views/site/docs/edit.py
app/soc/views/site/docs/list.py
app/soc/views/site/home.py
app/soc/views/site/settings.py
app/soc/views/site/sponsor/list.py
app/soc/views/site/sponsor/profile.py
app/soc/views/site/user/list.py
app/soc/views/site/user/profile.py
app/soc/views/sponsor/profile.py
app/soc/views/user/profile.py
app/soc/views/user/roles.py
--- a/app/soc/views/docs/show.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/docs/show.py	Thu Oct 16 15:22:41 2008 +0000
@@ -36,12 +36,14 @@
 
 DEF_DOCS_PUBLIC_TMPL = 'soc/docs/public.html'
 
-def public(request, partial_path=None, link_name=None,
+def public(request, page=None, partial_path=None, link_name=None,
            template=DEF_DOCS_PUBLIC_TMPL):
   """How the "general public" sees a Document.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     partial_path: the Document's site-unique "path" extracted from the URL,
       minus the trailing link_name
     link_name: the last portion of the Document's site-unique "path"
@@ -75,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)
+    return simple.errorResponse(request, error, template, context, page)
 
   doc.content = helper.templates.unescape(doc.content)
   context['document'] = doc
--- a/app/soc/views/person/profile.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/person/profile.py	Thu Oct 16 15:22:41 2008 +0000
@@ -54,12 +54,14 @@
     exclude = ['user']
 
 
-def edit(request, program=None, link_name=None,
+def edit(request, page=None, program=None, link_name=None,
          template='soc/person/profile/edit.html'):
   """View for a Person to modify the properties of a Person Model.
 
   Args:
     request: the standard django 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 path to use for rendering the template.
 
   Returns:
--- a/app/soc/views/simple.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/simple.py	Thu Oct 16 15:22:41 2008 +0000
@@ -35,7 +35,7 @@
 
 
 def public(request, template='soc/base.html', link_name=None,
-                         context=None):
+           context=None, page=None):
   """A simple template view that expects a link_name extracted from the URL.
 
   Args:
@@ -44,10 +44,12 @@
       of templates)
     link_name: a site-unique "link_name" (usually extracted from the URL)
     context: the context dict supplied to the template, which is modified
-        (so supply a copy if such modification is not acceptable)
-      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
+      (so supply a copy if such modification is not acceptable)
+    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.
@@ -62,7 +64,7 @@
     if link_name:
       user = id_user.getUserFromLinkNameOr404(link_name)
   except out_of_band.ErrorResponse, error:
-    return errorResponse(request, error, template, context)
+    return errorResponse(request, error, template, context, page)
 
   context['link_name'] = link_name
   context['link_name_user'] = user
@@ -73,7 +75,7 @@
 DEF_ERROR_TMPL = 'soc/error.html'
 
 
-def errorResponse(request, error, template, context):
+def errorResponse(request, error, template, context, page=None):
   """Displays an error page for an out_of_band.ErrorResponse exception.
   
   Args:
@@ -82,10 +84,12 @@
     template: the "sibling" template (or a search list of such templates)
       from which to construct the error.html template name (or names)
     context: the context dict supplied to the template, which is modified
-        (so supply a copy if such modification is not acceptable)
-      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
+      (so supply a copy if such modification is not acceptable)
+    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:
@@ -106,7 +110,8 @@
 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):
+def requestLogin(request, template, context=None, login_message_fmt=None,
+                 page=None):
   """Displays a login request page with custom message and login link.
   
   Args:
@@ -118,9 +123,11 @@
       named format specifiers for any of the keys in context, but should at
       least contain %(sign_in)s
     context: the context dict supplied to the template, which is modified
-        (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
+      (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 15:12:00 2008 +0000
+++ b/app/soc/views/site/docs/edit.py	Thu Oct 16 15:22:41 2008 +0000
@@ -108,11 +108,13 @@
 
 DEF_SITE_DOCS_CREATE_TMPL = 'soc/site/docs/edit.html'
 
-def create(request, template=DEF_SITE_DOCS_CREATE_TMPL):
+def create(request, page=None, template=DEF_SITE_DOCS_CREATE_TMPL):
   """View for a Developer to create a new Document entity.
 
   Args:
     request: the standard django 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 public.html template name (or names)
 
@@ -164,12 +166,14 @@
                                       required=False)
 
 
-def edit(request, partial_path=None, link_name=None,
+def edit(request, page=None, partial_path=None, link_name=None,
          template=DEF_SITE_DOCS_EDIT_TMPL):
   """View for a Developer to modify the properties of a Document Model entity.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     partial_path: the Document's site-unique "path" extracted from the URL,
       minus the trailing link_name
     link_name: the last portion of the Document's site-unique "path"
@@ -202,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)
+    return simple.errorResponse(request, error, template, context, page)
 
   if request.method == 'POST':
     form = EditForm(request.POST)
@@ -267,12 +271,14 @@
   return helper.responses.respond(request, template, context)
 
 
-def delete(request, partial_path=None, link_name=None,
+def delete(request, page=None, partial_path=None, link_name=None,
            template=DEF_SITE_DOCS_EDIT_TMPL):
   """Request handler for a Developer to delete Document Model entity.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     partial_path: the Document's site-unique "path" extracted from the URL,
       minus the trailing link_name
     link_name: the last portion of the Document's site-unique "path"
@@ -304,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)
+    return simple.errorResponse(request, error, template, context, page)
 
   if existing_doc:
     document.logic.delete(existing_doc)
--- a/app/soc/views/site/docs/list.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/docs/list.py	Thu Oct 16 15:22:41 2008 +0000
@@ -37,11 +37,13 @@
 DEF_SITE_DOCS_LIST_ALL_TMPL = 'soc/site/docs/list/all.html'
 
 
-def all(request, template=DEF_SITE_DOCS_LIST_ALL_TMPL):
+def all(request, page=None, template=DEF_SITE_DOCS_LIST_ALL_TMPL):
   """Show a list of all Documents (limit rows per page).
   
   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 an alternate template name (or names)
 
--- a/app/soc/views/site/home.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/home.py	Thu Oct 16 15:22:41 2008 +0000
@@ -38,11 +38,13 @@
 
 DEF_SITE_HOME_PUBLIC_TMPL = 'soc/site/home/public.html'
 
-def public(request, template=DEF_SITE_HOME_PUBLIC_TMPL):
+def public(request, page=None, template=DEF_SITE_HOME_PUBLIC_TMPL):
   """How the "general public" sees the Melange site home page.
 
   Args:
     request: the standard django 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 path to use for rendering the template.
 
   Returns:
--- a/app/soc/views/site/settings.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/settings.py	Thu Oct 16 15:22:41 2008 +0000
@@ -95,11 +95,13 @@
 
 DEF_SITE_HOME_EDIT_TMPL = 'soc/site/settings/edit.html'
 
-def edit(request, template=DEF_SITE_HOME_EDIT_TMPL):
+def edit(request, page=None, template=DEF_SITE_HOME_EDIT_TMPL):
   """View for Developer to edit content of Melange site home page.
 
   Args:
     request: the standard django 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 path to use for rendering the template.
 
   Returns:
--- a/app/soc/views/site/sponsor/list.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/sponsor/list.py	Thu Oct 16 15:22:41 2008 +0000
@@ -37,8 +37,19 @@
 
 DEF_SITE_SPONSOR_LIST_ALL_TMPL = 'soc/group/list/all.html'
 
-def all(request, template=DEF_SITE_SPONSOR_LIST_ALL_TMPL):
+def all(request, page=None, template=DEF_SITE_SPONSOR_LIST_ALL_TMPL):
   """Show a list of all Sponsors (limit rows per page).
+  
+  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 an alternate template name (or names)
+
+  Returns:
+    A subclass of django.http.HttpResponse which either contains the form to
+    be filled out, or a redirect to the correct view in the interface.
   """
 
   try:
--- a/app/soc/views/site/sponsor/profile.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/sponsor/profile.py	Thu Oct 16 15:22:41 2008 +0000
@@ -88,11 +88,13 @@
                           ' <a href="/site/sponsor/profile">Create ' \
                           'a New Sponsor</a> page.'
 
-def edit(request, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
+def edit(request, page=None, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
   """View for a Developer to modify the properties of a Sponsor Model entity.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the Sponsor's site-unique "link_name" extracted from the URL
     template: the "sibling" template (or a search list of such templates)
       from which to construct the public.html template name (or names)
@@ -121,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)
+    return simple.errorResponse(request, error, template, context, page)
      
   if request.method == 'POST':
     if existing_sponsor:
@@ -137,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)
+          return simple.errorResponse(request, error, template, context, page)
       
       fields = {}      
       
@@ -199,17 +201,19 @@
 
 DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL = 'soc/group/profile/edit.html'
 
-def create(request, template=DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL):
+def create(request, page=None, template=DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL):
   """create() view is same as edit() view, but with no link_name supplied.
   """
-  return edit(request, link_name=None, template=template)
+  return edit(request, page, link_name=None, template=template)
 
 
-def delete(request, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
+def delete(request, page=None, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
   """Request handler for a Developer to delete Sponsor Model entity.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the Sponsor's site-unique "link_name" extracted from the URL
     template: the "sibling" template (or a search list of such templates)
       from which to construct the public.html template name (or names)
@@ -235,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)
+    return simple.errorResponse(request, error, template, context, page)
 
   if existing_sponsor:
     # TODO(pawel.solyga): Create specific delete method for Sponsor model
--- a/app/soc/views/site/user/list.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/user/list.py	Thu Oct 16 15:22:41 2008 +0000
@@ -38,11 +38,13 @@
 DEF_SITE_USER_LIST_ALL_TMPL = 'soc/site/user/list/all.html'
 
 
-def all(request, template=DEF_SITE_USER_LIST_ALL_TMPL):
+def all(request, page=None, template=DEF_SITE_USER_LIST_ALL_TMPL):
   """Show a list of all Users (limit rows per page).
   
   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 an alternate template name (or names)
 
--- a/app/soc/views/site/user/profile.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/site/user/profile.py	Thu Oct 16 15:22:41 2008 +0000
@@ -94,11 +94,13 @@
 
 DEF_SITE_USER_PROFILE_LOOKUP_TMPL = 'soc/site/user/profile/lookup.html'
 
-def lookup(request, template=DEF_SITE_USER_PROFILE_LOOKUP_TMPL):
+def lookup(request, page=None, template=DEF_SITE_USER_PROFILE_LOOKUP_TMPL):
   """View for a Developer to look up a User Model entity.
 
   Args:
     request: the standard django 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 public.html template name (or names)
 
@@ -248,11 +250,13 @@
                           ' <a href="/site/user/profile">Create ' \
                           'a New User</a> page.'
 
-def edit(request, link_name=None, template=DEF_SITE_USER_PROFILE_EDIT_TMPL):
+def edit(request, page=None, link_name=None, template=DEF_SITE_USER_PROFILE_EDIT_TMPL):
   """View for a Developer to modify the properties of a User Model entity.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the User's site-unique "link_name" extracted from the URL
     template: the "sibling" template (or a search list of such templates)
       from which to construct the public.html template name (or names)
@@ -279,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)
+    return simple.errorResponse(request, error, template, context, page)
 
 
   if request.method == 'POST':
@@ -397,11 +401,13 @@
 
 DEF_SITE_CREATE_USER_PROFILE_TMPL = 'soc/site/user/profile/edit.html'
 
-def create(request, template=DEF_SITE_CREATE_USER_PROFILE_TMPL):
+def create(request, page=None, template=DEF_SITE_CREATE_USER_PROFILE_TMPL):
   """View for a Developer to create a new User Model entity.
 
   Args:
     request: the standard django 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 public.html template name (or names)
 
--- a/app/soc/views/sponsor/profile.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/sponsor/profile.py	Thu Oct 16 15:22:41 2008 +0000
@@ -33,11 +33,14 @@
 
 DEF_SPONSOR_PUBLIC_TMPL = 'soc/group/profile/public.html'
 
-def public(request, link_name=None, template=DEF_SPONSOR_PUBLIC_TMPL):
+def public(request, page=None, link_name=None, 
+           template=DEF_SPONSOR_PUBLIC_TMPL):
   """How the "general public" sees the Sponsor profile.
 
   Args:
     request: the standard django request object.
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the Sponsor's site-unique "link_name" extracted from the URL
     template: the template path to use for rendering the template.
 
@@ -51,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)
+    return simple.errorResponse(request, error, template, context, page)
 
   link_name_sponsor.description = \
       helper.templates.unescape(link_name_sponsor.description)
--- a/app/soc/views/user/profile.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/user/profile.py	Thu Oct 16 15:22:41 2008 +0000
@@ -82,11 +82,14 @@
   SUBMIT_MSG_PARAM_NAME: SUBMIT_MSG_PROFILE_SAVED,
 }
 
-def edit(request, link_name=None, template=DEF_USER_PROFILE_EDIT_TMPL):
+def edit(request, page=None, link_name=None, 
+         template=DEF_USER_PROFILE_EDIT_TMPL):
   """View for a User to modify the properties of a User Model entity.
 
   Args:
     request: the standard django request object
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the User's site-unique "link_name" extracted from the URL
     template: the template path to use for rendering the template
 
@@ -101,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,
+    return simple.requestLogin(request, template, context, page=page,
         # 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>'
@@ -110,7 +113,7 @@
 
   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)
+    return simple.public(request, template, link_name, context, page)
 
   link_name_user = None
 
@@ -120,13 +123,13 @@
         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)
+    return simple.errorResponse(request, error, template, context, page)
   
   # 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)
+    return simple.public(request, template, link_name, context, page)
 
   if request.method == 'POST':
     form = UserForm(request.POST)
@@ -178,7 +181,7 @@
   return helper.responses.respond(request, template, context)
 
 
-def create(request, template=DEF_USER_PROFILE_EDIT_TMPL):
+def create(request, page=None, template=DEF_USER_PROFILE_EDIT_TMPL):
   """create() view is same as edit() view, but with no link_name supplied.
   """
-  return edit(request, link_name=None, template=template)
+  return edit(request, page, link_name=None, template=template)
--- a/app/soc/views/user/roles.py	Thu Oct 16 15:12:00 2008 +0000
+++ b/app/soc/views/user/roles.py	Thu Oct 16 15:22:41 2008 +0000
@@ -33,12 +33,14 @@
 from soc.views.helpers import response_helpers
 
 
-def dashboard(request, link_name=None,
+def dashboard(request, page=None, link_name=None,
               template='soc/user/roles/dashboard.html'):
   """A per-User dashboard of that User's Roles on the site.
 
   Args:
     request: the standard django request object.
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the User's site-unique "link_name" extracted from the URL
     template: the template path to use for rendering the template.
 
@@ -60,12 +62,14 @@
       template, {'template': template})
 
 
-def public(request, link_name=None,
+def public(request, page=None, link_name=None,
            template='soc/user/roles/public.html'):
   """A "general public" view of a User's Roles on the site.
 
   Args:
     request: the standard django request object.
+    page: a soc.logic.site.page.Page object which is abstraction that combines 
+      a Django view with sidebar menu info
     link_name: the User's site-unique "link_name" extracted from the URL
     template: the template path to use for rendering the template.