[Mpuls-commits] r5488 - base/trunk/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 21 12:56:42 CEST 2011


Author: ludwig
Date: 2011-10-21 12:56:42 +0200 (Fri, 21 Oct 2011)
New Revision: 5488

Modified:
   base/trunk/mpulsweb/controllers/case.py
   base/trunk/mpulsweb/controllers/case_bundle.py
Log:
Issue 395: Improvement of the design of the buildCaseList method.
Now in case_bundle.py is one function, which is used by the CaseController and
the CaseBundleController.


Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py	2011-10-21 10:01:14 UTC (rev 5487)
+++ base/trunk/mpulsweb/controllers/case.py	2011-10-21 10:56:42 UTC (rev 5488)
@@ -31,8 +31,8 @@
 from mpulsweb.model.agencysettings import Agency
 
 from mpulsweb.controllers.formularpage import get_rendered_page
+from mpulsweb.controllers.case_bundle import buildCaseList
 
-
 log = logging.getLogger(__name__)
 
 
@@ -96,20 +96,6 @@
         return render(template)
 
     #
-    # helper method 
-    # return a string containing a html list with the overview_fields of 
-    # the case 
-    #
-    def _buildOneCaseList(self, case):
-        list = ["<ul>"]
-        overview_fields = case.get_overview_fields()
-        list.append("<li>%s</li>" % ", ".join([
-                escape(NA(case.get_value(f.name))) for f in overview_fields]))
-        list.append("</ul>")
-        return list
-
-
-    #
     # Delete
     #
 
@@ -135,7 +121,7 @@
                               " deletion?%s The case will not be editable"
                               " afterwards, and submited to the administration"
                               " for deletion.<br>") \
-                            % "\n".join(self._buildOneCaseList(case))
+                            % "\n".join(buildCaseList([case]))
 
             c.url_yes = h.url_for(controller='/case', action='markForDelete',
                                   id=id, confirmed=1)
@@ -157,7 +143,7 @@
                               " <b>not needed for evaluations</b> anymore."
                               "<br><br>Do you want to delete the case "
                               "from the server?%s<br>") \
-                            % "\n".join(self._buildOneCaseList(case))
+                            % "\n".join(buildCaseList([case]))
             c.url_yes = h.url_for(controller='/case', action='delete',
                                   id=id, confirmed=1)
             c.url_no = h.url_for(controller='/case_overview')
@@ -247,7 +233,7 @@
                                u" for final anonymisation.</p>"
                                u"<p><b>The case document is going to be"
                                u" anonymised in phase </b>%s<b>!</b><br>""") \
-                             % ("\n".join(self._buildOneCaseList(case)),
+                             % ("\n".join(buildCaseList([case])),
                                  " ".join(phase_name)))
             c.url_yes = h.url_for(controller='/case', action='markForAnonymize',
                                   id=id, confirmed=1)
@@ -400,7 +386,7 @@
                               u" After it the case will not be available you."
                               u" The anonymised case will still be considered"
                               u" for the analysis.<br>") \
-                            % "\n".join(self._buildOneCaseList(case))
+                            % "\n".join(buildCaseList([case]))
             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)
@@ -515,7 +501,7 @@
             c.dialog_text = _("Do you really want to restore the case?%s"
                               " The case will be editable afterwards again"
                               " for the users.<br>") \
-                            % "\n".join(self._buildOneCaseList(case))
+                            % "\n".join(buildCaseList([case]))
             c.url_yes = h.url_for(controller='/case', action='restore', id=id,
                                   confirmed=1)
             c.url_no = h.url_for(controller='/case_overview')

Modified: base/trunk/mpulsweb/controllers/case_bundle.py
===================================================================
--- base/trunk/mpulsweb/controllers/case_bundle.py	2011-10-21 10:01:14 UTC (rev 5487)
+++ base/trunk/mpulsweb/controllers/case_bundle.py	2011-10-21 10:56:42 UTC (rev 5488)
@@ -220,16 +220,6 @@
         case_bundle = MpulsCaseBundle(filtered)
         return case_bundle
 
-    def _buildCaseList(self, bundle):
-        list = ["<ul>"]
-        cases = bundle.getCases()
-        overview_fields = cases[0].get_overview_fields()
-        for case in cases:
-            list.append("<li>%s</li>" % ", ".join([
-                escape(NA(case.get_value(f.name))) for f in overview_fields]))
-        list.append("</ul>")
-        return list
-
     def _build_casebundle(self, options):
         if options.get('all_cases') > 0:
             ids = options["all_ids"]
@@ -283,7 +273,7 @@
                                        'Do you really want to delete the'
                                        ' following cases?%s',
                                        len(case_bundle.getCases()))
-                             % "\n".join(self._buildCaseList(case_bundle)))
+                             % "\n".join(buildCaseList(case_bundle.getCases())))
             c.url_yes = url_for(controller='/case_bundle', action='markDelete',
                                 confirmed=1)
             c.url_no = url_for(controller='/case_overview')
@@ -304,7 +294,7 @@
                                        'Do you really want to delete the'
                                        ' following cases?%s',
                                        total)
-                             % "\n".join(self._buildCaseList(case_bundle))
+                             % "\n".join(buildCaseList(case_bundle.getCases()))
                              + _("Warning!"
                                  " Deleting cases will erase all data of the"
                                  " case irrecoverably!<br>\n"
@@ -380,7 +370,7 @@
                           u" the administrators for review for the definite"
                           u" anonymisation.%s",
                           total)
-                % "\n".join(self._buildCaseList(case_bundle)))
+                % "\n".join(buildCaseList(case_bundle.getCases())))
             c.url_yes = url_for(controller='/case_bundle',
                                 action='markAnonymize', confirmed=1)
             c.url_no = url_for(controller='/case_overview')
@@ -459,7 +449,7 @@
                           u" The anonymised cases will still be considered"
                           u" in the analysis.%s",
                           total)
-                % "\n".join(self._buildCaseList(case_bundle)))
+                % "\n".join(buildCaseList(case_bundle.getCases())))
             c.url_yes = url_for(controller='/case_bundle', action='anonymize',
                                 confirmed=1)
             c.url_no = url_for(controller='/case_overview')
@@ -536,7 +526,7 @@
                           u'Do you really want to restore the following cases?'
                           u' They will be available again for editing.%s',
                           len(case_bundle.getCases()))
-                % "\n".join(self._buildCaseList(case_bundle)))
+                % "\n".join(buildCaseList(case_bundle.getCases())))
             c.url_yes = url_for(controller='/case_bundle', action='restore',
                                 confirmed=1)
             c.url_no = url_for(controller='/case_overview')
@@ -609,7 +599,7 @@
                 'exportselection': [i.getName() for i in c.pages]}
         c.dialog_title = ungettext(u'Export case?', u'Export cases?',
                                    len(case_bundle.getCases()))
-        c.dialog_text = "\n".join(self._buildCaseList(case_bundle))
+        c.dialog_text = "\n".join(buildCaseList(case_bundle.getCases()))
         # logbook export is only possible for XML exports and if the
         # logbook is actually activated in the application.
         c.allow_logbook_export = (g.mpuls_config.is_enabled('case-module',
@@ -675,4 +665,15 @@
                                      **extra)
         return data(request.environ, self.start_response)
 
+def buildCaseList(cases):
+    """From a list of cases this function builds a html list of overview fields 
+of the cases."""
+    list = ["<ul>"]
+    overview_fields = cases[0].get_overview_fields()
+    for case in cases:
+        list.append("<li>%s</li>" % ", ".join([
+            escape(NA(case.get_value(f.name))) for f in overview_fields]))
+    list.append("</ul>")
+    return list
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list