[Mpuls-commits] r372 - in wasko/trunk: . waskaweb/lib waskaweb/model waskaweb/model/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Mar 16 15:11:54 CET 2009


Author: teichmann
Date: 2009-03-16 15:11:45 +0100 (Mon, 16 Mar 2009)
New Revision: 372

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/lib/renderer.py
   wasko/trunk/waskaweb/model/casedocument.py
   wasko/trunk/waskaweb/model/data.py
   wasko/trunk/waskaweb/model/io/document.py
Log:
Added rendering of conditionals.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-16 11:10:33 UTC (rev 371)
+++ wasko/trunk/ChangeLog.txt	2009-03-16 14:11:45 UTC (rev 372)
@@ -1,5 +1,15 @@
 2009-03-16	Sascha L. Teichmann	<teichmann at intevation.de>
 
+	* waskaweb/model/data.py: Added ConditionalNode.
+
+	* waskaweb/model/casedocument.py: added eval logic for ConditionalNodes
+
+	* waskaweb/model/io/document.py: Make conditionals loadable.
+
+	* waskaweb/lib/renderer.py: render conditional.
+
+2009-03-16	Sascha L. Teichmann	<teichmann at intevation.de>
+
 	* waskaweb/converter/wasko_v1v2.py: convert v1 nat_staat to v2 nat_staat.
 
 2009-03-12	Sascha L. Teichmann	<teichmann at intevation.de>

Modified: wasko/trunk/waskaweb/lib/renderer.py
===================================================================
--- wasko/trunk/waskaweb/lib/renderer.py	2009-03-16 11:10:33 UTC (rev 371)
+++ wasko/trunk/waskaweb/lib/renderer.py	2009-03-16 14:11:45 UTC (rev 372)
@@ -112,6 +112,9 @@
     def getWarning(self, dataID):
         return ""
 
+    def evaluate(self, expr):
+        return True
+
 def digits(n):
     d, c = 10, 1
     while n >= d: d *= 10; c += 1
@@ -152,11 +155,14 @@
         page     = None, 
         errors   = None, 
         warnings = None,
-        nc       = None):
+        nc       = None,
+        formed   = None
+    ):
         FormData.__init__(self, file_cache.get_image, help)
         self.page     = page
         self.errors   = errors
         self.warnings = warnings
+        self.formed   = formed
         if nc:
             self.nc      = nc #NodeComponent List []
             self.widgets = self.nc[0].allWidgets()
@@ -164,6 +170,9 @@
             self.nc      = []
             self.widgets = {} 
 
+    def evaluate(self, expr):
+        return self.formed.evaluate(expr)
+
     def getData(self, dataID):
         if not self.errors is None:
             try:
@@ -359,6 +368,20 @@
 
         self.toTarget(Item("".join(out)), node.getTarget())
 
+    def _renderConditional(self, conditional):
+        expr = conditional.getExpr()
+
+        if expr and not self.formdata.evaluate(expr):
+            ro = not conditional.isInvisible()
+            if ro:
+                old_ro = self.ro_mode
+                self.ro_mode = True
+                self._renderRecursive(conditional)
+                self.ro_mode = old_ro
+        else:
+            self._renderRecursive(conditional)
+
+
     def _renderMatrix(self, node):
         description = node.getDescription()
         name        = node.getName()
@@ -895,6 +918,8 @@
                 self._renderRadio(child)
             elif isinstance(child, data.PageNode):
                 self._renderPage(child)
+            elif isinstance(child, data.ConditionalNode):
+                self._renderConditional(child)
             else:
                 self.toTarget(Text(self._renderRecursive(child)), child.getTarget())
 

Modified: wasko/trunk/waskaweb/model/casedocument.py
===================================================================
--- wasko/trunk/waskaweb/model/casedocument.py	2009-03-16 11:10:33 UTC (rev 371)
+++ wasko/trunk/waskaweb/model/casedocument.py	2009-03-16 14:11:45 UTC (rev 372)
@@ -293,4 +293,13 @@
 
         return warnings
 
+    def evaluate(self, expr):
+        if not expr: return False
+        try:
+            okay = expr.evaluate(dict([
+                (n, self.getData(n)) for n in expr.getDependencies()]))
+        except:
+            okay = False
+        return okay
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: wasko/trunk/waskaweb/model/data.py
===================================================================
--- wasko/trunk/waskaweb/model/data.py	2009-03-16 11:10:33 UTC (rev 371)
+++ wasko/trunk/waskaweb/model/data.py	2009-03-16 14:11:45 UTC (rev 372)
@@ -119,6 +119,28 @@
         self.visit(collector.visitor)
         return collector.widgets
 
+class ConditionalNode(Node):
+
+    def __init__(self):
+        Node.__init__(self)
+        self.attributes["expr"]      = ""
+        self.attributes["invisible"] = ""
+        self.expr = None
+
+    def setAttribute(self, attrib, value, broadcast=True):
+        if attrib == "expr":
+            newExpr = Expr(value)
+            newExpr.compile()
+            self.expr = newExpr
+        Node.setAttribute(self, attrib, value, broadcast)
+
+    def setExpr(self, expr):
+        self.setAttribute('expr', expr)
+
+    def getExpr(self):
+        return self.expr
+
+
 class MatrixNode(GroupNode):
     def __init__(self):
         GroupNode.__init__(self)

Modified: wasko/trunk/waskaweb/model/io/document.py
===================================================================
--- wasko/trunk/waskaweb/model/io/document.py	2009-03-16 11:10:33 UTC (rev 371)
+++ wasko/trunk/waskaweb/model/io/document.py	2009-03-16 14:11:45 UTC (rev 372)
@@ -54,6 +54,7 @@
 DATE_TAG            = u"date"
 TEXT_AREA_TAG       = u"textarea"
 RULE_TAG            = u"rule"
+CONDITIONAL_TAG     = u"conditional"
 
 namesToClasses = {
     DOCUMENT_TAG:        RootNode,
@@ -71,7 +72,9 @@
     TEXT_TAG:            TextLeaf,
     TEXT_AREA_TAG:       TextAreaLeaf,
     RULE_TAG:            RuleLeaf,
-    DATE_TAG:            DateLeaf}
+    DATE_TAG:            DateLeaf,
+    CONDITIONAL_TAG:     ConditionalNode
+    }
 
 factoryCreators = {
     DOCUMENT_TAG:        SimpleCreator(DocumentFactory,      RootNode),
@@ -80,6 +83,7 @@
     PAGE_TAG:            SimpleCreator(NodeFactory,          PageNode),
     GROUP_TAG:           SimpleCreator(NodeFactory,          GroupNode),
     MATRIX_TAG:          SimpleCreator(NodeFactory,          MatrixNode),
+    CONDITIONAL_TAG:     SimpleCreator(NodeFactory,          ConditionalNode),
     RADIO_TAG:           SimpleCreator(NodeFactory,          RadioNode),
     CHOICE_TAG:          SimpleCreator(NodeFactory,          ChoiceNode),
     EXT_CHOICE_LIST_TAG: SimpleCreator(NodeComponentFactory, ExternalChoiceListLeaf),
@@ -91,23 +95,7 @@
     RULE_TAG:            SimpleCreator(NodeComponentFactory, RuleLeaf),
     DATE_TAG:            SimpleCreator(NodeComponentFactory, DateLeaf)}
 
-classesToTagNames = {
-    RootNode:               DOCUMENT_TAG,
-    CaseNode:               CASE_TAG,
-    LogbookNode:            LOGBOOK_TAG,
-    PageNode:               PAGE_TAG,
-    GroupNode:              GROUP_TAG,
-    MatrixNode:             MATRIX_TAG,
-    RadioNode:              RADIO_TAG,
-    ChoiceNode:             CHOICE_TAG,
-    IntLeaf:                INT_TAG,
-    InfoLeaf:               INFO_TAG,
-    TextLeaf:               TEXT_TAG,
-    TextAreaLeaf:           TEXT_AREA_TAG,
-    DateLeaf:               DATE_TAG,
-    ExternalChoiceListLeaf: EXT_CHOICE_LIST_TAG,
-    RuleLeaf:               RULE_TAG,
-    BoolLeaf:               BOOL_TAG }
+classesToTagNames = dict([(v, k) for k, v in namesToClasses.iteritems()])
 
 def openDocument(path, documentFactoryCreator = None):
     builder = SAXBuilder(path)



More information about the Mpuls-commits mailing list