app/soc/views/site/sponsor/profile.py
changeset 290 2a92b866ed40
parent 278 b0e2d509b5c3
child 292 1cece5192e26
equal deleted inserted replaced
289:1b63d17d5b62 290:2a92b866ed40
   163         # redirect to aggressively remove 'Profile saved' query parameter
   163         # redirect to aggressively remove 'Profile saved' query parameter
   164         return http.HttpResponseRedirect(request.path)
   164         return http.HttpResponseRedirect(request.path)
   165       
   165       
   166       # referrer was us, so select which submit message to display
   166       # referrer was us, so select which submit message to display
   167       # (may display no message if ?s=0 parameter is not present)
   167       # (may display no message if ?s=0 parameter is not present)
   168       context['submit_message'] = (
   168       context['notice'] = (
   169           helper.requests.getSingleIndexedParamValue(
   169           helper.requests.getSingleIndexedParamValue(
   170               request, profile.SUBMIT_MSG_PARAM_NAME,
   170               request, profile.SUBMIT_MSG_PARAM_NAME,
   171               values=profile.SUBMIT_MESSAGES))    
   171               values=profile.SUBMIT_MESSAGES))    
   172               
   172               
   173       # populate form with the existing Sponsor entity
   173       # populate form with the existing Sponsor entity
   189 
   189 
   190 def create(request, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
   190 def create(request, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
   191   """create() view is same as edit() view, but with no linkname supplied.
   191   """create() view is same as edit() view, but with no linkname supplied.
   192   """
   192   """
   193   return edit(request, linkname=None, template=template)
   193   return edit(request, linkname=None, template=template)
       
   194 
       
   195 
       
   196 def delete(request, linkname=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
       
   197   """Request handler for a Developer to delete Sponsor Model entity.
       
   198 
       
   199   Args:
       
   200     request: the standard django request object
       
   201     linkname: the Sponsor's site-unique "linkname" extracted from the URL
       
   202     template: the "sibling" template (or a search list of such templates)
       
   203       from which to construct the public.html template name (or names)
       
   204 
       
   205   Returns:
       
   206     A subclass of django.http.HttpResponse which redirects 
       
   207     to /site/sponsor/list.
       
   208   """
       
   209   # create default template context for use with any templates
       
   210   context = helper.responses.getUniversalContext(request)
       
   211 
       
   212   alt_response = simple.getAltResponseIfNotDeveloper(request,
       
   213                                                      context=context)
       
   214   if alt_response:
       
   215     return alt_response
       
   216 
       
   217   existing_sponsor = None
       
   218 
       
   219   # try to fetch Sponsor entity corresponding to linkname if one exists    
       
   220   try:
       
   221     existing_sponsor = soc.logic.sponsor.getSponsorIfLinkName(linkname)
       
   222   except out_of_band.ErrorResponse, error:
       
   223     # show custom 404 page when link name doesn't exist in Datastore
       
   224     error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG
       
   225     return simple.errorResponse(request, error, template, context)
       
   226 
       
   227   if existing_sponsor:
       
   228     sponsor.deleteSponsor(existing_sponsor)
       
   229 
       
   230   return http.HttpResponseRedirect('/site/sponsor/list')