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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 19 15:45:57 CEST 2011


Author: bh
Date: 2011-08-19 15:45:55 +0200 (Fri, 19 Aug 2011)
New Revision: 5247

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

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


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-08-18 20:12:51 UTC (rev 5246)
+++ base/trunk/ChangeLog	2011-08-19 13:45:55 UTC (rev 5247)
@@ -1,3 +1,21 @@
+2011-08-19  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/controllers/case.py (CaseController.anonymize): Prepare
+	for the possibility that anonymizing a case may raise arbitrary
+	exception which will be the case when the meta-server is involved,
+	for instance. The actual anonymization is handled in the new
+	method _do_anonymize_case which is the place where the more
+	specific exceptions can be handled. The anonymize method itself is
+	mostly scaffolding to ask for confirmation and handle exceptions
+	not caught by _do_anonymize_case in a generic way.
+	(CaseController._do_anonymize_case): Extracted from anonymize so
+	that derived classes can easily extend the exception handling, if
+	necessary.
+
+	* mpulsweb/templates/casemanagement/dialogs/failed_anonymize.mako:
+	New. Template for errors detected during anonymization in the case
+	controller.
+
 2011-08-18  Bernhard Herzog  <bh at intevation.de>
 
 	* mpulsweb/controllers/case.py (CaseController._markForAnonymize):

Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py	2011-08-18 20:12:51 UTC (rev 5246)
+++ base/trunk/mpulsweb/controllers/case.py	2011-08-19 13:45:55 UTC (rev 5247)
@@ -225,37 +225,55 @@
         confirmed = self._checkBool(confirmed)
         case = self._loadCase(id)
 
-        # First check if the case is in a state which allows anonymization
+        # Check whether the case can actually be anonymized.
         try:
             case.check_anonymizeability()
         except ConsistenceCheckException, e:
-            c.dialog_title =  _(u"""Anonymising not possible.""")
+            c.dialog_title = _(u"Anonymising not possible.")
             c.dialog_text = h.literal(e.value)
             c.url_ok = h.url_for(controller='/case', action='digest', id=id)
             return render('/casemanagement/dialogs/failed_markanonymize.mako')
 
-        # Ok, show confirmation dialog if the user really wants to anonymize the
-        # case.
-        if confirmed == 1:
-            case.anonymize()
-            c.dialog_title = _(u"""Case document anonymised!""")
-            c.dialog_text = _(u"""\
-The personal data of the case document has been deleted and the case document
-is removed from the overview. Please click on OK, to get back to the overview.""")
-            c.url_ok = h.url_for(controller="/case_overview")
-            return render('/casemanagement/dialogs/success_anonymize.mako')
-        else:
+        # Show confirmation dialog if necessary.
+        if not confirmed:
             c.context = "../main.mako"
-            c.dialog_title = _(u"""Do make anonymous?""")
-            c.dialog_text =  _("""Do you really want to anonymise the case and
-irrecovably lose the associated personal data? After it the case will
-not be available you. The anonymised case will still be considered for
-the analysis.""")
+            c.dialog_title = _(u"Do make anonymous?")
+            c.dialog_text = _(u"Do you really want to anonymise the case and"
+                              u" irrecovably lose the associated personal"
+                              u" data?"
+                              u" After it the case will not be available you."
+                              u" The anonymised case will still be considered"
+                              u" for the analysis.")
             c.url_yes = h.url_for(controller='/case', action='anonymize',
                                   id=id, confirmed=1)
             c.url_no = h.url_for(controller='/case', action='digest', id=id)
             return render('/casemanagement/dialogs/confirm_anonymize.mako')
 
+        try:
+            return self._do_anonymize_case(case)
+        except Exception:
+            log.exception("Exception while trying to anonymize case %s", id)
+            c.dialog_title = _("Case document not anonymized!")
+            c.dialog_text = _("The case can not be anonymized because of an"
+                              " unexpected problem.")
+            c.url_ok = h.url_for(controller="/case_overview")
+            return render('/casemanagement/dialogs/failed_anonymize.mako')
+
+    def _do_anonymize_case(self, case):
+        """Anonymize 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 anonymize method.
+        """
+        case.anonymize()
+        c.dialog_title = _(u"""Case document anonymised!""")
+        c.dialog_text = _(u"The personal data of the case document has been"
+                          u" deleted and the case document is removed from"
+                          u" the overview. Please click on OK, to get back to"
+                          u" the overview.")
+        c.url_ok = h.url_for(controller="/case_overview")
+        return render('/casemanagement/dialogs/success_anonymize.mako')
+
+
     #
     # Restore
     #

Added: base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_anonymize.mako
===================================================================
--- base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_anonymize.mako	2011-08-18 20:12:51 UTC (rev 5246)
+++ base/trunk/mpulsweb/templates/casemanagement/dialogs/failed_anonymize.mako	2011-08-19 13:45:55 UTC (rev 5247)
@@ -0,0 +1,15 @@
+## -*- coding: utf-8 -*- 
+<%inherit file="/main.mako" />
+<%
+  case = session.get('case')
+%>
+<%def name="buildNavipath()">
+  ${parent.buildNavipath()}
+  %if case:
+    <li><a href="${h.url_for(controller='/case', action='select', id=case.id, confirmed=1)}">${_('Selected case documents')}</a></li>
+  %else:
+    <li><a href="${h.url_for(controller='/case_overview')}">${_('Case document overview')}</a></li>
+  %endif
+  <li><a href="#">${_('Anonymize case document')}</a></li>
+</%def>
+<%include file="/dialogs/failed.mako" />



More information about the Mpuls-commits mailing list