app/soc/views/site/user/profile.py
changeset 482 839740b061ad
parent 481 94834a1e6c01
child 483 70f21691b0e1
equal deleted inserted replaced
481:94834a1e6c01 482:839740b061ad
    94     
    94     
    95 
    95 
    96 DEF_SITE_USER_PROFILE_LOOKUP_TMPL = 'soc/user/lookup.html'
    96 DEF_SITE_USER_PROFILE_LOOKUP_TMPL = 'soc/user/lookup.html'
    97 
    97 
    98 @decorators.view
    98 @decorators.view
    99 def lookup(request, page=None, template=DEF_SITE_USER_PROFILE_LOOKUP_TMPL):
    99 def lookup(request, page_name=None, template=DEF_SITE_USER_PROFILE_LOOKUP_TMPL):
   100   """View for a Developer to look up a User Model entity.
   100   """View for a Developer to look up a User Model entity.
   101 
   101 
   102   Args:
   102   Args:
   103     request: the standard django request object
   103     request: the standard django request object
   104     page: a soc.logic.site.page.Page object which is abstraction that combines 
   104     page: a soc.logic.site.page.Page object which is abstraction that combines 
   116   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
   116   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
   117     return alt_response.response()
   117     return alt_response.response()
   118 
   118 
   119   # create default template context for use with any templates
   119   # create default template context for use with any templates
   120   context = helper.responses.getUniversalContext(request)
   120   context = helper.responses.getUniversalContext(request)
   121   context['page'] = page
   121   context['page_name'] = page_name
   122 
   122 
   123   user = None  # assume that no User entity will be found
   123   user = None  # assume that no User entity will be found
   124   form = None  # assume blank form needs to be displayed
   124   form = None  # assume blank form needs to be displayed
   125   lookup_message = ugettext_lazy('Enter information to look up a User.')
   125   lookup_message = ugettext_lazy('Enter information to look up a User.')
   126   email_error = None  # assume no email look-up errors
   126   email_error = None  # assume no email look-up errors
   261 DEF_CREATE_NEW_USER_MSG = ' You can create a new user by visiting' \
   261 DEF_CREATE_NEW_USER_MSG = ' You can create a new user by visiting' \
   262                           ' <a href="/site/user/profile">Create ' \
   262                           ' <a href="/site/user/profile">Create ' \
   263                           'a New User</a> page.'
   263                           'a New User</a> page.'
   264 
   264 
   265 @decorators.view
   265 @decorators.view
   266 def edit(request, page=None, link_name=None,
   266 def edit(request, page_name=None, link_name=None,
   267          template=DEF_SITE_USER_PROFILE_EDIT_TMPL):
   267          template=DEF_SITE_USER_PROFILE_EDIT_TMPL):
   268   """View for a Developer to modify the properties of a User Model entity.
   268   """View for a Developer to modify the properties of a User Model entity.
   269 
   269 
   270   Args:
   270   Args:
   271     request: the standard django request object
   271     request: the standard django request object
   285   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
   285   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
   286     return alt_response.response()
   286     return alt_response.response()
   287 
   287 
   288   # create default template context for use with any templates
   288   # create default template context for use with any templates
   289   context = helper.responses.getUniversalContext(request)
   289   context = helper.responses.getUniversalContext(request)
   290   context['page'] = page
   290   context['page_name'] = page_name
   291 
   291 
   292   user = None  # assume that no User entity will be found
   292   user = None  # assume that no User entity will be found
   293 
   293 
   294   # try to fetch User entity corresponding to link_name if one exists
   294   # try to fetch User entity corresponding to link_name if one exists
   295   try:
   295   try:
   296     if link_name:
   296     if link_name:
   297       user = accounts.getUserFromLinkNameOr404(link_name)
   297       user = accounts.getUserFromLinkNameOr404(link_name)
   298   except out_of_band.ErrorResponse, error:
   298   except out_of_band.ErrorResponse, error:
   299     # show custom 404 page when link name doesn't exist in Datastore
   299     # show custom 404 page when link name doesn't exist in Datastore
   300     error.message = error.message + DEF_CREATE_NEW_USER_MSG
   300     error.message = error.message + DEF_CREATE_NEW_USER_MSG
   301     return simple.errorResponse(request, page, error, template, context)
   301     return simple.errorResponse(request, page_name, error, template, context)
   302 
   302 
   303 
   303 
   304   if request.method == 'POST':
   304   if request.method == 'POST':
   305     form = EditForm(request.POST)
   305     form = EditForm(request.POST)
   306 
   306 
   417 
   417 
   418 
   418 
   419 DEF_SITE_CREATE_USER_PROFILE_TMPL = 'soc/user/edit.html'
   419 DEF_SITE_CREATE_USER_PROFILE_TMPL = 'soc/user/edit.html'
   420 
   420 
   421 @decorators.view
   421 @decorators.view
   422 def create(request, page=None, template=DEF_SITE_CREATE_USER_PROFILE_TMPL):
   422 def create(request, page_name=None, template=DEF_SITE_CREATE_USER_PROFILE_TMPL):
   423   """View for a Developer to create a new User Model entity.
   423   """View for a Developer to create a new User Model entity.
   424 
   424 
   425   Args:
   425   Args:
   426     request: the standard django request object
   426     request: the standard django request object
   427     page: a soc.logic.site.page.Page object which is abstraction that combines 
   427     page: a soc.logic.site.page.Page object which is abstraction that combines 
   439   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
   439   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
   440     return alt_response.response()
   440     return alt_response.response()
   441 
   441 
   442   # create default template context for use with any templates
   442   # create default template context for use with any templates
   443   context = helper.responses.getUniversalContext(request)
   443   context = helper.responses.getUniversalContext(request)
   444   context['page'] = page
   444   context['page_name'] = page_name
   445 
   445 
   446   if request.method == 'POST':
   446   if request.method == 'POST':
   447     form = CreateForm(request.POST)
   447     form = CreateForm(request.POST)
   448 
   448 
   449     if form.is_valid():
   449     if form.is_valid():