app/soc/views/user/profile.py
changeset 358 843d83b87282
parent 355 9b3f26057f74
child 361 465e4df617de
equal deleted inserted replaced
357:9bd78a5073c2 358:843d83b87282
    80 
    80 
    81 SUBMIT_PROFILE_SAVED_PARAMS = {
    81 SUBMIT_PROFILE_SAVED_PARAMS = {
    82   SUBMIT_MSG_PARAM_NAME: SUBMIT_MSG_PROFILE_SAVED,
    82   SUBMIT_MSG_PARAM_NAME: SUBMIT_MSG_PROFILE_SAVED,
    83 }
    83 }
    84 
    84 
    85 def edit(request, link_name=None, template=DEF_USER_PROFILE_EDIT_TMPL):
    85 def edit(request, page=None, link_name=None, 
       
    86          template=DEF_USER_PROFILE_EDIT_TMPL):
    86   """View for a User to modify the properties of a User Model entity.
    87   """View for a User to modify the properties of a User Model entity.
    87 
    88 
    88   Args:
    89   Args:
    89     request: the standard django request object
    90     request: the standard django request object
       
    91     page: a soc.logic.site.page.Page object which is abstraction that combines 
       
    92       a Django view with sidebar menu info
    90     link_name: the User's site-unique "link_name" extracted from the URL
    93     link_name: the User's site-unique "link_name" extracted from the URL
    91     template: the template path to use for rendering the template
    94     template: the template path to use for rendering the template
    92 
    95 
    93   Returns:
    96   Returns:
    94     A subclass of django.http.HttpResponse which either contains the form to
    97     A subclass of django.http.HttpResponse which either contains the form to
    99   # create default template context for use with any templates
   102   # create default template context for use with any templates
   100   context = helper.responses.getUniversalContext(request)
   103   context = helper.responses.getUniversalContext(request)
   101 
   104 
   102   if (not id) and (not link_name):
   105   if (not id) and (not link_name):
   103     # not logged in, and no link name, so request that the user sign in 
   106     # not logged in, and no link name, so request that the user sign in 
   104     return simple.requestLogin(request, template, context,
   107     return simple.requestLogin(request, template, context, page=page,
   105         # TODO(tlarsen): /user/profile could be a link to a help page instead
   108         # TODO(tlarsen): /user/profile could be a link to a help page instead
   106         login_message_fmt='To create a new'
   109         login_message_fmt='To create a new'
   107                           ' <a href="/user/profile">User Profile</a>'
   110                           ' <a href="/user/profile">User Profile</a>'
   108                           ' or modify an existing one, you must first'
   111                           ' or modify an existing one, you must first'
   109                           ' <a href="%(sign_in)s">sign in</a>.')
   112                           ' <a href="%(sign_in)s">sign in</a>.')
   110 
   113 
   111   if (not id) and link_name:
   114   if (not id) and link_name:
   112     # not logged in, so show read-only public profile for link_name user
   115     # not logged in, so show read-only public profile for link_name user
   113     return simple.public(request, template, link_name, context)
   116     return simple.public(request, template, link_name, context, page)
   114 
   117 
   115   link_name_user = None
   118   link_name_user = None
   116 
   119 
   117   # try to fetch User entity corresponding to link_name if one exists
   120   # try to fetch User entity corresponding to link_name if one exists
   118   try:
   121   try:
   119       if link_name:
   122       if link_name:
   120         link_name_user = id_user.getUserFromLinkNameOr404(link_name)
   123         link_name_user = id_user.getUserFromLinkNameOr404(link_name)
   121   except out_of_band.ErrorResponse, error:
   124   except out_of_band.ErrorResponse, error:
   122     # show custom 404 page when link name doesn't exist in Datastore
   125     # show custom 404 page when link name doesn't exist in Datastore
   123     return simple.errorResponse(request, error, template, context)
   126     return simple.errorResponse(request, error, template, context, page)
   124   
   127   
   125   # link_name_user will be None here if link name was already None...
   128   # link_name_user will be None here if link name was already None...
   126   if link_name_user and (link_name_user.id != id):
   129   if link_name_user and (link_name_user.id != id):
   127     # link_name_user exists but is not the currently logged in Google Account,
   130     # link_name_user exists but is not the currently logged in Google Account,
   128     # so show public view for that (other) User entity
   131     # so show public view for that (other) User entity
   129     return simple.public(request, template, link_name, context)
   132     return simple.public(request, template, link_name, context, page)
   130 
   133 
   131   if request.method == 'POST':
   134   if request.method == 'POST':
   132     form = UserForm(request.POST)
   135     form = UserForm(request.POST)
   133 
   136 
   134     if form.is_valid():
   137     if form.is_valid():
   176 
   179 
   177   context['form'] = form
   180   context['form'] = form
   178   return helper.responses.respond(request, template, context)
   181   return helper.responses.respond(request, template, context)
   179 
   182 
   180 
   183 
   181 def create(request, template=DEF_USER_PROFILE_EDIT_TMPL):
   184 def create(request, page=None, template=DEF_USER_PROFILE_EDIT_TMPL):
   182   """create() view is same as edit() view, but with no link_name supplied.
   185   """create() view is same as edit() view, but with no link_name supplied.
   183   """
   186   """
   184   return edit(request, link_name=None, template=template)
   187   return edit(request, page, link_name=None, template=template)