[Mpuls-commits] r421 - in wasko/trunk: . waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 20 12:14:49 CET 2009


Author: teichmann
Date: 2009-03-20 12:14:47 +0100 (Fri, 20 Mar 2009)
New Revision: 421

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/model/data.py
   wasko/trunk/waskaweb/model/datapage.py
Log:
Save page: If a there are conditionals on the page only modify fields that are 'active' (container conditionals evaluate to true). 



Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-20 10:22:46 UTC (rev 420)
+++ wasko/trunk/ChangeLog.txt	2009-03-20 11:14:47 UTC (rev 421)
@@ -1,5 +1,14 @@
 2009-03-20	Sascha L. Teichmann <teichmann at intevation.de>
 
+	* waskaweb/model/datapage.py: If a there are conditionals on the
+	  page only modify fields that are 'active' (container conditionals 
+	  evaluate to true). 
+
+	* waskaweb/model/data.py: Added ConditionalWidgetCollector to
+	  allow collection of 'active' fields only.
+
+2009-03-20	Sascha L. Teichmann <teichmann at intevation.de>
+
 	* waskaweb/lib/renderer.py: Evaluate conditionals in a way not to
 	  destroy the layout.
 

Modified: wasko/trunk/waskaweb/model/data.py
===================================================================
--- wasko/trunk/waskaweb/model/data.py	2009-03-20 10:22:46 UTC (rev 420)
+++ wasko/trunk/waskaweb/model/data.py	2009-03-20 11:14:47 UTC (rev 421)
@@ -61,6 +61,30 @@
         return VISIT_CONTINUE
 
 
+class ConditionalWidgetCollector(object):
+
+    def __init__(self, evaluator = lambda expr: True):
+        self.widgets   = []
+        self.evaluator = evaluator
+
+    def visitor(self, nc):
+        if isinstance(nc, Node):
+            if isinstance(nc, ConditionalNode):
+                expr = nc.getExpr()
+                if expr and not self.evaluator(expr):
+                    return VISIT_IGNORE_CHILDREN
+            elif isinstance(nc, (RadioNode, ChoiceNode)):
+                self.widgets.append(nc)
+                return VISIT_IGNORE_CHILDREN
+            elif isinstance(nc, GroupNode) and nc.isRepeat() and nc != self:
+                return VISIT_IGNORE_CHILDREN
+        elif isinstance(nc, Leaf) and not isinstance(nc,
+            (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
+            self.widgets.append(nc)
+
+        return VISIT_CONTINUE
+
+
 class FilteredNodeComponentProxy:
     def __init__(self, params):
         self.params = params

Modified: wasko/trunk/waskaweb/model/datapage.py
===================================================================
--- wasko/trunk/waskaweb/model/datapage.py	2009-03-20 10:22:46 UTC (rev 420)
+++ wasko/trunk/waskaweb/model/datapage.py	2009-03-20 11:14:47 UTC (rev 421)
@@ -29,7 +29,7 @@
 #
 
 from waskaweb.model.semantic import ErrorItem, SematicError, checkAndConvert
-from waskaweb.model.data     import RuleLeaf
+from waskaweb.model.data     import RuleLeaf, ConditionalWidgetCollector
 
 from waskaweb.lib.db         import db
 
@@ -131,7 +131,6 @@
             self.widgets = self.nc.allWidgets()
             self.items   = [w.getName() for w in self.widgets]
 
-
     def _fetchData(self):
         self.__lazyCheck()
         try:
@@ -162,10 +161,11 @@
 
     def save(self, params, old_errors, document):
 
-        self.__lazyCheck()
+        wc = ConditionalWidgetCollector(document.evaluate)
+        self.nc.visit(wc.visitor)
 
-        nwidgets      = self.widgets
-        widgets_names = self.items
+        nwidgets      = wc.widgets
+        widgets_names = [w.getName() for w in wc.widgets]
         pageName      = self.nc.getName()
 
         dbPage = self



More information about the Mpuls-commits mailing list