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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 1 16:06:10 CEST 2010


Author: bh
Date: 2010-10-01 16:06:09 +0200 (Fri, 01 Oct 2010)
New Revision: 3856

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/renderer.py
Log:
* mpulsweb/lib/renderer.py
(RepeatGroupRenderer.get_conditional_parents): New method to
determine the conditionals from the instance tree containing a
given tree item.
(RepeatGroupRenderer.get_field_info): Evaluate the invisibility
conditionals containing the field and return (None, None) if the
field would be invisible in the rendered repeat group instance
anyway to indicate that it should not be rendered in the digest
either.
(RepeatGroupRenderer.render_digest): Do not render fields that
would be invisible in the rendered repeat group instance.
Fixes mpuls/issue1103


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-10-01 14:05:13 UTC (rev 3855)
+++ base/trunk/ChangeLog	2010-10-01 14:06:09 UTC (rev 3856)
@@ -1,3 +1,18 @@
+2010-10-01  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/lib/renderer.py
+	(RepeatGroupRenderer.get_conditional_parents): New method to
+	determine the conditionals from the instance tree containing a
+	given tree item.
+	(RepeatGroupRenderer.get_field_info): Evaluate the invisibility
+	conditionals containing the field and return (None, None) if the
+	field would be invisible in the rendered repeat group instance
+	anyway to indicate that it should not be rendered in the digest
+	either.
+	(RepeatGroupRenderer.render_digest): Do not render fields that
+	would be invisible in the rendered repeat group instance.
+	Fixes mpuls/issue1103
+
 2010-10-01  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* mpulsweb/model/phase.py (Phase.getDescription): Return unescaped

Modified: base/trunk/mpulsweb/lib/renderer.py
===================================================================
--- base/trunk/mpulsweb/lib/renderer.py	2010-10-01 14:05:13 UTC (rev 3855)
+++ base/trunk/mpulsweb/lib/renderer.py	2010-10-01 14:06:09 UTC (rev 3856)
@@ -917,6 +917,8 @@
             for field in fields:
                 description, value = self.get_field_info(case_id, rg_identifier,
                                                          field)
+                if description is None:
+                    continue
                 out.append('<tr>')
                 out.append('<td class="label">')
                 out.append(tag("a", href=url_for(controller="/navigation",
@@ -937,8 +939,21 @@
         return "".join(out)
 
     def get_field_info(self, case_id, rg_identifier, field):
-        """Return description and formatted value for the given digest field"""
+        """Return description and formatted value for the given digest field.
+        If the item referred to by the field would be invisible in the
+        rendered repeat group instance due to visibility conditionals,
+        the method returns (None, None) to indicate that it shouldn't be
+        rendered in the digest either.
+        """
         item = self.it.getItem('%s:%s:%s' % (field, rg_identifier, case_id))
+
+        # check whether the item would be visible according to the
+        # conditionals containing it.
+        for conditional in self.get_conditional_parents(item):
+            if (conditional.getMeta().isInvisible()
+                and not self.it.evaluate_conditional(conditional)):
+                return None, None
+
         meta = self._getMeta(item)
         value = item.getValue()
         if isinstance(meta, data.DateLeaf):
@@ -956,7 +971,20 @@
                     break
         return (meta.getDescription(), value)
 
+    def get_conditional_parents(self, item):
+        """Return a list with the conditionals containing item.
 
+        The conditionals are the conditional nodes from the intance
+        tree.  The order of the conditionals in the return value is from
+        root to leaf.
+        """
+        conditionals = []
+        while item:
+            if isinstance(item.getMeta(), data.ConditionalNode):
+                conditionals.append(item)
+            item = item.getParent()
+        return reversed(conditionals)
+
     def render(self, showNext=False):
         out = []
         out.append('<div class="widget">')



More information about the Mpuls-commits mailing list