app/soc/views/site/docs/edit.py
changeset 314 dfaf249c12b2
parent 313 c25b1b680ba7
child 316 9efdc7bc3565
equal deleted inserted replaced
313:c25b1b680ba7 314:dfaf249c12b2
   276     form = CreateForm()
   276     form = CreateForm()
   277 
   277 
   278   context['form'] = form
   278   context['form'] = form
   279 
   279 
   280   return helper.responses.respond(request, template, context)
   280   return helper.responses.respond(request, template, context)
       
   281 
       
   282 
       
   283 def delete(request, partial_path=None, link_name=None,
       
   284            template=DEF_SITE_DOCS_EDIT_TMPL):
       
   285   """Request handler for a Developer to delete Document Model entity.
       
   286 
       
   287   Args:
       
   288     request: the standard django request object
       
   289     partial_path: the Document's site-unique "path" extracted from the URL,
       
   290       minus the trailing link_name
       
   291     link_name: the last portion of the Document's site-unique "path"
       
   292       extracted from the URL
       
   293     template: the "sibling" template (or a search list of such templates)
       
   294       from which to construct the public.html template name (or names)
       
   295 
       
   296   Returns:
       
   297     A subclass of django.http.HttpResponse which redirects 
       
   298     to /site/docs/list.
       
   299   """
       
   300 
       
   301   try:
       
   302     access.checkIsDeveloper(request)
       
   303   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
       
   304     return alt_response.response()
       
   305 
       
   306   # create default template context for use with any templates
       
   307   context = helper.responses.getUniversalContext(request)
       
   308 
       
   309   existing_doc = None
       
   310   path = path_link_name.combinePath([partial_path, link_name])
       
   311 
       
   312   # try to fetch Document entity corresponding to path if one exists    
       
   313   try:
       
   314     if path:
       
   315       existing_doc = document.logic.getFromFields(partial_path=partial_path,
       
   316                                                   link_name=link_name)
       
   317   except out_of_band.ErrorResponse, error:
       
   318     # show custom 404 page when path doesn't exist in Datastore
       
   319     error.message = error.message + DEF_CREATE_NEW_DOC_MSG
       
   320     return simple.errorResponse(request, error, template, context)
       
   321 
       
   322   if existing_doc:
       
   323     document.logic.delete(existing_doc)
       
   324 
       
   325   return http.HttpResponseRedirect('/site/docs/list')