[Mpuls-commits] r2722 - in base/trunk: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 20 12:49:34 CEST 2010


Author: bh
Date: 2010-05-20 12:49:33 +0200 (Thu, 20 May 2010)
New Revision: 2722

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/renderer.py
Log:
* mpulsweb/lib/renderer.py (RepeatGroupRenderer.render_digest)
(RepeatGroupRenderer.render): Rework these methods a little to
avoid some problems that could occur if the rg_digests haven't
been set properly.  In particular the default values used for
missing items were lists where dictionaries were expected by the
code.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-05-19 14:12:20 UTC (rev 2721)
+++ base/trunk/ChangeLog	2010-05-20 10:49:33 UTC (rev 2722)
@@ -1,3 +1,12 @@
+2010-05-20  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/lib/renderer.py (RepeatGroupRenderer.render_digest)
+	(RepeatGroupRenderer.render): Rework these methods a little to
+	avoid some problems that could occur if the rg_digests haven't
+	been set properly.  In particular the default values used for
+	missing items were lists where dictionaries were expected by the
+	code.
+
 2010-05-19  Bernhard Herzog  <bh at intevation.de>
 
 	* mpulsweb/lib/renderer.py: fix formatting.

Modified: base/trunk/mpulsweb/lib/renderer.py
===================================================================
--- base/trunk/mpulsweb/lib/renderer.py	2010-05-19 14:12:20 UTC (rev 2721)
+++ base/trunk/mpulsweb/lib/renderer.py	2010-05-20 10:49:33 UTC (rev 2722)
@@ -915,14 +915,10 @@
             digests = {}
         self.rg_digests = digests
 
-    def render_digest(self, rg):
+    def render_digest(self, rg, fields):
         out = []
         case_id = rg.getIdentifier().split(':')[-1]
 
-        fields = self.rg_digests.get(self._getMeta(rg).getName(),
-                                     []).get('fields')
-        log.debug(fields)
-
         out.append('<table class="rgdigest">')
         if not fields:
             log.warning("No digest specification for repeat group %r",
@@ -977,46 +973,51 @@
 
         # Sorting of RG.
         class SortDummy:
-            def __init__(self, rg, it, case_id, field):
+            def __init__(self, rg, it, case_id, sort_field, fields):
                 self.rg = rg
                 self.value = str(it.getItem('%s:%s:%s'
-                                            % (field,
+                                            % (sort_field,
                                                rg.getInternalIdentifier(),
                                                case_id)).getValue())
+                self.fields = fields
+                print "RepeatGroupRenderer.render.SortDummy.__init__", fields
+                print "RepeatGroupRenderer.render.SortDummy.__init__", str(self.value)
 
         unsorted_items = []
         reverse_order = False
         if len(items) > 0:
             rg = items[0]
             case_id = rg.getIdentifier().split(':')[-1]
-            fields = self.rg_digests.get(self._getMeta(rg).getName(),
-                                         []).get('fields')
-            sort_field = self.rg_digests.get(self._getMeta(rg).getName(),
-                                             []).get('sort_field', fields[0])
-            sort_order = self.rg_digests.get(self._getMeta(rg).getName(),
-                                             []).get('sort_order')
-            for rg in items:
-                unsorted_items.append(SortDummy(rg, self.it, case_id,
-                                                sort_field))
-            if sort_order == "desc":
-                reverse_order = True
+            digest_spec = self.rg_digests.get(self._getMeta(rg).getName())
+            if digest_spec is None:
+                log.error("No digest specification for %r", rg)
+            else:
+                fields = digest_spec.get('fields')
+                sort_field = digest_spec.get('sort_field', fields[0])
+                sort_order = digest_spec.get('sort_order')
+                for rg in items:
+                    unsorted_items.append(SortDummy(rg, self.it, case_id,
+                                                    sort_field, fields))
+                if sort_order == "desc":
+                    reverse_order = True
         sorted_items = sorted(unsorted_items, key=lambda rg: rg.value,
                               reverse=reverse_order)
 
-        for num, rg in enumerate([sd.rg for sd in sorted_items]):
+        for sd in sorted_items:
             out.append('<tr>')
             out.append('<td>')
-            out.append(self.render_digest(rg))
+            out.append(self.render_digest(sd.rg, sd.fields))
             out.append('</td>')
             out.append('<td class="actions">')
-            out.append(tag("a", href=("/navigation/select_branch/%s"
-                                      % rg.getChildren()[0].getIdentifier())))
+            out.append(tag("a",
+                           href=("/navigation/select_branch/%s"
+                                 % sd.rg.getChildren()[0].getIdentifier())))
             out.append(tag("img", src="/images/icons/open_active_22.png",
                            border="0", alt=_('view'), title=_('view')))
             out.append("</a>")
             if not self.ro_mode:
                 out.append(tag("a", href=("/repeatgroup/delete/%s"
-                                          % rg.getIdentifier())))
+                                          % sd.rg.getIdentifier())))
                 out.append(tag("img", src="/images/icons/delete_active_22.png",
                                border="0", alt=_('delete'), title=_('delete')))
                 out.append("</a>")



More information about the Mpuls-commits mailing list