[Mpuls-commits] r5244 - in base/trunk: . mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Aug 18 18:37:30 CEST 2011


Author: bh
Date: 2011-08-18 18:37:29 +0200 (Thu, 18 Aug 2011)
New Revision: 5244

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/case_bundle.py
Log:
* mpulsweb/controllers/case_bundle.py
(CaseBundleController.anonymize): Improve error reporting. This is
basically the same as the improved error reporting implemented for
markAnonymize. It already includes the performance improvement
achieved by fewer calls to case_bundle.getCases().


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-08-18 16:18:59 UTC (rev 5243)
+++ base/trunk/ChangeLog	2011-08-18 16:37:29 UTC (rev 5244)
@@ -1,6 +1,14 @@
 2011-08-18  Bernhard Herzog  <bh at intevation.de>
 
 	* mpulsweb/controllers/case_bundle.py
+	(CaseBundleController.anonymize): Improve error reporting. This is
+	basically the same as the improved error reporting implemented for
+	markAnonymize. It already includes the performance improvement
+	achieved by fewer calls to case_bundle.getCases().
+
+2011-08-18  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/controllers/case_bundle.py
 	(CaseBundleController.markAnonymize): Initialize the variable
 	total earlier and use it instead of "len(case_bundle.getCases())"
 	in two places. That expression is horribly inefficient because it

Modified: base/trunk/mpulsweb/controllers/case_bundle.py
===================================================================
--- base/trunk/mpulsweb/controllers/case_bundle.py	2011-08-18 16:18:59 UTC (rev 5243)
+++ base/trunk/mpulsweb/controllers/case_bundle.py	2011-08-18 16:37:29 UTC (rev 5244)
@@ -413,21 +413,11 @@
         confirmed = self._checkBool(confirmed)
         c.context = "../main.mako"
         case_bundle = session.get('casebundle')
-        if confirmed == 1:
-            num = case_bundle.anonymize()
-            c.dialog_title = ungettext(u"Case anonymised!",
-                                       u"Cases anonymised!",
-                                       num)
-            c.dialog_text = (ungettext(u"%s case was successfully anonymised.",
-                                       u"%s cases were successfully anonymised.",
-                                       num) % str(num)
-                             + " " + _("Please click OK to continue."))
-            c.url_ok = url_for(controller='/case_overview')
-            del session['casebundle']
-            return render ('/casebundle/dialogs/success_anonymize.mako')
-        else:
+        total = case_bundle.numDatasets()
+
+        if not confirmed:
             c.dialog_title = ungettext(u'Anonymise case?', u'Anonymise cases?',
-                                       len(case_bundle.getCases()))
+                                       total)
             c.dialog_text = (
                 ungettext(u"Do you really want to anonymise the case and"
                           u" irrevocably lose its personal data? The case"
@@ -439,13 +429,59 @@
                           u" will not be available for editing anymore."
                           u" The anonymised cases will still be considered"
                           u" in the analysis.%s",
-                          len(case_bundle.getCases()))
+                          total)
                 % "\n".join(self._buildCaseList(case_bundle)))
             c.url_yes = url_for(controller='/case_bundle', action='anonymize',
                                 confirmed=1)
             c.url_no = url_for(controller='/case_overview')
             return render('/casebundle/dialogs/confirm_anonymize.mako')
 
+        successes = case_bundle.anonymize()
+        failures = total - successes
+
+        if not failures:
+            c.dialog_title = ungettext(u"Case anonymised!",
+                                       u"Cases anonymised!",
+                                       total)
+            c.dialog_text = (
+                ungettext(u"The selected case has been anonymised"
+                          u" successfully.",
+                          u"The selected cases have been anonymised"
+                          u" successfully.",
+                          total)
+                + " " + _("Please click OK to continue."))
+            template = '/casebundle/dialogs/success_anonymize.mako'
+        elif successes > 0:
+            # successes != total and successes > 0 means total
+            # is also greater than 1, so we can always assume the
+            # plural when talking about all selected cases
+            c.dialog_title = _(u"Not all cases anonymized.")
+            c.dialog_text = (
+                ungettext(u"One of the selected cases could not be"
+                          u" anonymised.",
+                          u"%(failures)s of the selected cases could"
+                          u" not be anonymised.",
+                          failures)
+                % dict(failures=failures)
+                + " " + _("Please click OK to continue."))
+            template = '/casebundle/dialogs/failure_anonymize.mako'
+        else:
+            c.dialog_title = ungettext(u"Case not anonymized.",
+                                       u"Cases not anonymized.",
+                                       total)
+            c.dialog_text = (ungettext(u"The selected case has not been"
+                                       u" anonymized.",
+                                       u"None of the selected cases have been"
+                                       u" anonymized.",
+                                       total)
+                             + " " + _("Please click OK to continue."))
+            template = '/casebundle/dialogs/failure_anonymize.mako'
+
+        c.url_ok = url_for(controller='/case_overview')
+        del session['casebundle']
+        return render(template)
+
+
     # RESTORE
     @checkRole(('admin'))
     def restore(self, confirmed):



More information about the Mpuls-commits mailing list