# HG changeset patch # User Pawel Solyga # Date 1223919680 0 # Node ID dfaf249c12b2a7637de3626b4eebf636a0f44946 # Parent c25b1b680ba7feedc9470b6bb991662401ed9a4e Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality. Patch by: Pawel Solyga Review by: to-be-reviewed diff -r c25b1b680ba7 -r dfaf249c12b2 app/soc/logic/site/map.py --- a/app/soc/logic/site/map.py Mon Oct 13 06:19:43 2008 +0000 +++ b/app/soc/logic/site/map.py Mon Oct 13 17:41:20 2008 +0000 @@ -162,6 +162,14 @@ short_name='Modify Site Document', parent=site_home_edit) +site_docs_delete = page.Page( + page.Url( + r'^site/docs/%s/delete$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, + 'soc.views.site.docs.edit.delete'), + 'Site: Delete Existing Document', + short_name='Delete Site Document', + parent=site_home_edit) + site_docs_list = page.Page( page.Url( r'^site/docs/list$', diff -r c25b1b680ba7 -r dfaf249c12b2 app/soc/templates/soc/site/docs/edit.html --- a/app/soc/templates/soc/site/docs/edit.html Mon Oct 13 06:19:43 2008 +0000 +++ b/app/soc/templates/soc/site/docs/edit.html Mon Oct 13 17:41:20 2008 +0000 @@ -55,6 +55,11 @@ + {% if existing_doc %} + + + + {% endif %} {% endblock %} diff -r c25b1b680ba7 -r dfaf249c12b2 app/soc/views/site/docs/edit.py --- a/app/soc/views/site/docs/edit.py Mon Oct 13 06:19:43 2008 +0000 +++ b/app/soc/views/site/docs/edit.py Mon Oct 13 17:41:20 2008 +0000 @@ -278,3 +278,48 @@ context['form'] = form return helper.responses.respond(request, template, context) + + +def delete(request, 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 + 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" + 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) + + Returns: + A subclass of django.http.HttpResponse which redirects + to /site/docs/list. + """ + + try: + access.checkIsDeveloper(request) + except soc.views.out_of_band.AccessViolationResponse, alt_response: + return alt_response.response() + + # create default template context for use with any templates + context = helper.responses.getUniversalContext(request) + + existing_doc = None + path = path_link_name.combinePath([partial_path, link_name]) + + # try to fetch Document entity corresponding to path if one exists + try: + if path: + existing_doc = document.logic.getFromFields(partial_path=partial_path, + link_name=link_name) + 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) + + if existing_doc: + document.logic.delete(existing_doc) + + return http.HttpResponseRedirect('/site/docs/list') \ No newline at end of file diff -r c25b1b680ba7 -r dfaf249c12b2 app/soc/views/site/home.py --- a/app/soc/views/site/home.py Mon Oct 13 06:19:43 2008 +0000 +++ b/app/soc/views/site/home.py Mon Oct 13 17:41:20 2008 +0000 @@ -28,13 +28,12 @@ from google.appengine.api import users +from google.appengine.ext import db from django import http from django import shortcuts from django import newforms as forms - -import soc.logic.models.settings from soc.logic import models from soc.logic import out_of_band from soc.logic import validate @@ -43,14 +42,15 @@ from soc.views import simple from soc.views import helper from soc.views.helper import access -import soc.views.out_of_band + +import soc.logic.models.settings +import soc.models.document +import soc.models.site_settings import soc.views.helper.forms import soc.views.helper.responses import soc.views.helper.templates import soc.views.helper.widgets - -import soc.models.site_settings -import soc.models.document +import soc.views.out_of_band class DocumentForm(helper.forms.DbModelForm): @@ -114,7 +114,12 @@ if site_settings: context['site_settings'] = site_settings - site_doc = site_settings.home + + # check if ReferenceProperty to home Document is valid + try: + site_doc = site_settings.home + except db.Error: + site_doc = None if site_doc: site_doc.content = helper.templates.unescape(site_doc.content) @@ -185,7 +190,13 @@ if site_settings: # populate form with the existing SiteSettings entity settings_form = SiteSettingsForm(instance=site_settings) - site_doc = site_settings.home + + # check if ReferenceProperty to home Document is valid + try: + site_doc = site_settings.home + except db.Error: + site_doc = None + else: # no SiteSettings entity exists for this key_name, so show a blank form settings_form = SiteSettingsForm()