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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 17 15:08:10 CET 2009


Author: torsten
Date: 2009-02-17 15:08:05 +0100 (Tue, 17 Feb 2009)
New Revision: 263

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/model/data.py
   wasko/trunk/waskaweb/model/nodecomponents.py
   wasko/trunk/waskaweb/model/phases_factory.py
Log:
Ported WidgetCollector from Offline-Client


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-02-16 17:15:01 UTC (rev 262)
+++ wasko/trunk/ChangeLog.txt	2009-02-17 14:08:05 UTC (rev 263)
@@ -1,3 +1,13 @@
+2009-02-17	Torsten Irlaender  <torsten.irlaender at intevation.de>
+
+	Use Widgetcollector from offlineclient
+
+	* waskaweb/model/nodecomponents.py,
+	  waskaweb/model/data.py,
+	  waskaweb/model/phases_factory.py: Ported use of Widgetcollector from
+	  the offlineclient. It is now uses to select aal widgets when
+	  checking the phases.
+
 2009-02-16	Torsten Irlaender  <torsten.irlaender at intevation.de>
 
 	Implemented renderer and help-handling from the offline client

Modified: wasko/trunk/waskaweb/model/data.py
===================================================================
--- wasko/trunk/waskaweb/model/data.py	2009-02-16 17:15:01 UTC (rev 262)
+++ wasko/trunk/waskaweb/model/data.py	2009-02-17 14:08:05 UTC (rev 263)
@@ -41,6 +41,25 @@
 
 import waskaweb.model.io.document
 
+class WidgetCollector(object):
+
+    def __init__(self):
+        self.widgets = []
+
+    def visitor(self, nc):
+        if isinstance(nc, Node):
+            if isinstance(nc, (RadioNode, ChoiceNode)):
+                self.widgets.append(nc)
+                return VISIT_IGNORE_CHILDREN
+            if 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
@@ -63,26 +82,10 @@
         Node.__init__(self)
 
     def allWidgets(self):
+        collector = WidgetCollector()
+        self.visit(collector.visitor)
+        return collector.widgets
 
-        widgets = []
-
-        def visitor(nc):
-            if isinstance(nc, Node):
-                if isinstance(nc, (RadioNode, ChoiceNode)):
-                    widgets.append(nc)
-                    return VISIT_IGNORE_CHILDREN
-                if isinstance(nc, GroupNode) and nc.isRepeat():
-                    return VISIT_IGNORE_CHILDREN
-            elif isinstance(nc, Leaf) and not isinstance(nc, 
-                (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
-                widgets.append(nc)
-
-            return VISIT_CONTINUE
-
-        self.visit(visitor)
-
-        return widgets
-
 class GroupNode(Node):
     def __init__(self):
         Node.__init__(self)
@@ -104,26 +107,10 @@
         self.setAttribute("invisible", invisible)
 
     def allWidgets(self):
+        collector = WidgetCollector()
+        self.visit(collector.visitor)
+        return collector.widgets
 
-        widgets = []
-
-        def visitor(nc):
-            if isinstance(nc, Node):
-                if isinstance(nc, (RadioNode, ChoiceNode)):
-                    widgets.append(nc)
-                    return VISIT_IGNORE_CHILDREN
-                if isinstance(nc, GroupNode) and nc.isRepeat() and nc != self:
-                    return VISIT_IGNORE_CHILDREN
-            elif isinstance(nc, Leaf) and not isinstance(nc, 
-                (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
-                widgets.append(nc)
-
-            return VISIT_CONTINUE
-
-        self.visit(visitor)
-
-        return widgets
-
 class MatrixNode(GroupNode):
     def __init__(self):
         GroupNode.__init__(self)

Modified: wasko/trunk/waskaweb/model/nodecomponents.py
===================================================================
--- wasko/trunk/waskaweb/model/nodecomponents.py	2009-02-16 17:15:01 UTC (rev 262)
+++ wasko/trunk/waskaweb/model/nodecomponents.py	2009-02-17 14:08:05 UTC (rev 263)
@@ -303,6 +303,10 @@
                 if isinstance(nc, clazz):
                     yield nc
 
+    def visit(self, visitor):
+        if self.root:
+            self.root.visit(visitor)
+
     def walk(self):
         if self.root:
             for nc in self.root.walk():

Modified: wasko/trunk/waskaweb/model/phases_factory.py
===================================================================
--- wasko/trunk/waskaweb/model/phases_factory.py	2009-02-16 17:15:01 UTC (rev 262)
+++ wasko/trunk/waskaweb/model/phases_factory.py	2009-02-17 14:08:05 UTC (rev 263)
@@ -31,7 +31,7 @@
 from waskaweb.model.phases           import *
 from waskaweb.model.phase_transition import *
 
-from waskaweb.model.data             import PageNode
+from waskaweb.model.data             import PageNode, WidgetCollector
 
 IS_FILLED = \
 """(%(name)s IS NOT NULL
@@ -85,8 +85,10 @@
         phases, times = {}, {}
 
         all, all_times = [], []
-        
-        for nc in document.walk():
+
+        collector = WidgetCollector()
+        document.visit(collector.visitor)
+        for nc in collector.widgets:
             flags = nc.getFlags()
             if flags is None: continue
             for pair in flags.split(';'):
@@ -206,7 +208,6 @@
             select_terms.append(IS_FILLED % { 'name': a[0] })
 
         select = SELECT % ', '.join(select_terms)
-
         cur.execute(select, { 'id': ds_id })
         row = cur.fetchone()
         if not row: return False



More information about the Mpuls-commits mailing list