[Mpuls-commits] r5249 - in base/trunk: . mpulsweb/controllers mpulsweb/templates/casemanagement/dialogs

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 19 17:12:47 CEST 2011


Author: bh
Date: 2011-08-19 17:12:45 +0200 (Fri, 19 Aug 2011)
New Revision: 5249

Added:
   base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_delete.mako
Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/case.py
Log:
* mpulsweb/controllers/case.py (CaseController.delete): Prepare
for the possibility that deleting a case may raise arbitrary
exceptions, which will be the case when the meta-server is
involved, for instance. The actual deletion is handled in the new
method _do_delete_case which is the place where the more specific
exceptions can be handled. The delete method itself is mostly
scaffolding to ask for confirmation and handle exceptions not
caught by _do_delete_case in a generic way.
(CaseController._do_delete_case): Extracted from delete so that
derived classes can easily extend the exception handling, if
necessary.

* mpulsweb/templates/casemanagement/dialogs/failed_delete.mako:
New. Template for errors detected during deletion in the case
controller.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-08-19 14:33:00 UTC (rev 5248)
+++ base/trunk/ChangeLog	2011-08-19 15:12:45 UTC (rev 5249)
@@ -1,5 +1,23 @@
 2011-08-19  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/controllers/case.py (CaseController.delete): Prepare
+	for the possibility that deleting a case may raise arbitrary
+	exceptions, which will be the case when the meta-server is
+	involved, for instance. The actual deletion is handled in the new
+	method _do_delete_case which is the place where the more specific
+	exceptions can be handled. The delete method itself is mostly
+	scaffolding to ask for confirmation and handle exceptions not
+	caught by _do_delete_case in a generic way.
+	(CaseController._do_delete_case): Extracted from delete so that
+	derived classes can easily extend the exception handling, if
+	necessary.
+
+	* mpulsweb/templates/casemanagement/dialogs/failed_delete.mako:
+	New. Template for errors detected during deletion in the case
+	controller.
+
+2011-08-19  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/model/case.py (MpulsCase.anonymize): Simplify the
 	implementation and remove the exception handlers. The callers can
 	deal with the exceptions now.

Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py	2011-08-19 14:33:00 UTC (rev 5248)
+++ base/trunk/mpulsweb/controllers/case.py	2011-08-19 15:12:45 UTC (rev 5249)
@@ -90,26 +90,43 @@
     def delete(self, id, confirmed):
         id = self._checkInt(id)
         confirmed = self._checkBool(confirmed)
-        if confirmed == 1:
-            case = self._loadCase(id)
-            case.delete()
-            c.dialog_title = _("""Case document deleted!""")
-            c.dialog_text = _("""Click on OK to continue.""")
-            c.url_ok = h.url_for(controller="/case_overview")
-            return render('/casemanagement/dialogs/success_delete.mako')
-        else:
+
+        if not confirmed:
             c.context = "../main.mako"
             c.dialog_title = ungettext('Delete case?', 'Delete cases?', 1)
-            c.dialog_text = _("""Warning! On deleting the case all data will be erased
-irrecoverable!<br>Only delete the case if this case is <b>not needed for
-evaluations</b> anymore.<br><br>Do you want to delete the case from the
-server?""")
-
+            c.dialog_text = _("Warning! On deleting the case all data will"
+                              " be erased irrecoverable!<br>"
+                              "Only delete the case if this case is"
+                              " <b>not needed for evaluations</b> anymore."
+                              "<br><br>"
+                              "Do you want to delete the case from the server?")
             c.url_yes = h.url_for(controller='/case', action='delete',
                                   id=id, confirmed=1)
             c.url_no = h.url_for(controller='/case_overview')
             return render('/casemanagement/dialogs/confirm_delete.mako')
 
+        case = self._loadCase(id)
+        try:
+            return self._do_delete_case(case)
+        except Exception, e:
+            c.dialog_title = _("Case document not deleted!")
+            c.dialog_text = _("The case can not be deleted because of an"
+                              " unexpected problem.")
+            c.url_ok = h.url_for(controller="/case_overview")
+            return render('/casemanagement/dialogs/failed_delete.mako')
+
+    def _do_delete_case(self, case):
+        """Delete the case and return a HTML success or error message.
+        Derived classes may override or extend this method if they need
+        to handle specific exceptions raised by the case's delete method.
+        """
+        case.delete()
+        c.dialog_title = _("Case document deleted!")
+        c.dialog_text = _("Click on OK to continue.")
+        c.url_ok = h.url_for(controller="/case_overview")
+        return render('/casemanagement/dialogs/success_delete.mako')
+
+
     #
     # Anonymize
     #

Added: base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_delete.mako
===================================================================
--- base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_delete.mako	2011-08-19 14:33:00 UTC (rev 5248)
+++ base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_delete.mako	2011-08-19 15:12:45 UTC (rev 5249)
@@ -0,0 +1,8 @@
+## -*- coding: utf-8 -*- 
+<%inherit file="/main.mako" />
+<%def name="buildNavipath()">
+	${parent.buildNavipath()}
+        <li><a href="${h.url_for(controller='/case')}">${_('Case Management')}</a></li>
+	<li><a href="#">${_('Case document deleted!')}</a></li>
+</%def>
+<%include file="../../dialogs/failed.mako" />



More information about the Mpuls-commits mailing list