[Mpuls-commits] r685 - in waska/trunk: . waskaweb/lib waskaweb/model waskaweb/model/io
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 13 12:22:01 CET 2009
Author: torsten
Date: 2009-11-13 12:22:00 +0100 (Fri, 13 Nov 2009)
New Revision: 685
Modified:
waska/trunk/ChangeLog.txt
waska/trunk/waskaweb/lib/renderer.py
waska/trunk/waskaweb/model/data.py
waska/trunk/waskaweb/model/datapage.py
waska/trunk/waskaweb/model/io/document.py
Log:
Added rendering of conditionals
Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt 2009-11-13 11:20:06 UTC (rev 684)
+++ waska/trunk/ChangeLog.txt 2009-11-13 11:22:00 UTC (rev 685)
@@ -6,6 +6,14 @@
waskaweb/templates/casemanagement/caselist.mako: Fixed layout of
caselisting for IE7
+ Added rendering of conditionals
+
+ * waskaweb/model/datapage.py,
+ waskaweb/model/data.py,
+ waskaweb/model/io/document.py,
+ waskaweb/lib/renderer.py: Added conditionals and info dialog to
+ renderer
+
2009-11-12 Torsten Irlaender <torsten.irlaender at intevation.de>
Changed phase icons in overview
Modified: waska/trunk/waskaweb/lib/renderer.py
===================================================================
--- waska/trunk/waskaweb/lib/renderer.py 2009-11-13 11:20:06 UTC (rev 684)
+++ waska/trunk/waskaweb/lib/renderer.py 2009-11-13 11:22:00 UTC (rev 685)
@@ -27,7 +27,7 @@
# Authors:
# Sascha L. Teichmann <teichmann at intevation.de>
#
-
+from traceback import print_exc
from waskaweb.model.nodecomponents import Node
import waskaweb.lib.helpers as h
import waskaweb.lib.filters as F
@@ -42,6 +42,8 @@
TARGET=re.compile(r"(\w+)(?:|:(.+))$")
+DIALOG_SCHUELER1 = u'''<div class="form_errors"> <h1>Wichtiger Hinweis</h1><p>Schüler/innen dürfen nur dann ins Case Managagement aufgenommen werden, wenn sie sich im letzten Schulbesuchsjahr befinden und eine Übergangsprogrognose vorliegt.</p></div>'''
+
HELP = \
'''<span class="help"> <a href="%s" target="_blank">
<img src="/images/icons/form_help.png" border="0"
@@ -89,6 +91,9 @@
def getError(self, dataID):
return ""
+ def evaluate(self, expr):
+ return False
+
def digits(n):
d, c = 10, 1
while n >= d: d *= 10; c += 1
@@ -193,6 +198,15 @@
pass
return ""
+ def evaluate(self, expr):
+ values = {}
+ for d in expr.getDependencies():
+ values[d] = self.page.getData(d)
+ try:
+ ok = expr.evaluate(values)
+ except:
+ ok = False
+ return ok
class Text:
def __init__(self, txt):
@@ -344,6 +358,11 @@
return "No items given!"
out = []
+ # Render Error dialog
+ v1 = self.formdata.getData('letzte_jahr_allg_schule')
+ v2 = self.formdata.getData('prognose_liegt_vor')
+ if v1 == '0' or (v1 == '1' and v2 == '0'):
+ out.append(DIALOG_SCHUELER1)
if not self.ro_mode:
out.append('<form id="waska_form" action="')
if action: out.append(escape(action, True))
@@ -424,6 +443,23 @@
self.toTarget(Item("".join(out)), node.getTarget())
+ def _renderConditional(self, conditional):
+ expr = conditional.getExpr()
+ out = []
+ if expr and not self.formdata.evaluate(expr):
+ ro = not conditional.isInvisible()
+ if ro:
+ old_ro = self.ro_mode
+ self.ro_mode = True
+ for child in conditional.children:
+ self._renderChild(child)
+ self.ro_mode = old_ro
+ else:
+ self.toTarget(Text(""), conditional.getTarget())
+ else:
+ for child in conditional.children:
+ self._renderChild(child)
+
def _renderInfo(self, info):
if info.isInvisible(): return
text, depth = info.getValue(), visibleDepth(info)
@@ -830,6 +866,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: waska/trunk/waskaweb/model/data.py
===================================================================
--- waska/trunk/waskaweb/model/data.py 2009-11-13 11:20:06 UTC (rev 684)
+++ waska/trunk/waskaweb/model/data.py 2009-11-13 11:22:00 UTC (rev 685)
@@ -122,6 +122,55 @@
def sortChildren(self):
self.children.sort(key=lambda obj: obj.getAttribute('target'))
+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
+
+ def isInvisible(self):
+ return self.getAttribute("invisible") and True or False
+
+ def setInvisible(self):
+ invisible = invisible and "true" or ""
+ self.setAttribute("invisible", invisible)
+
+ def allWidgets(self):
+ widgets = []
+ self.visit(visitor)
+ 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
+ return widgets
+
class RadioNode(Node):
def __init__(self):
Node.__init__(self)
@@ -265,6 +314,7 @@
def __init__(self):
Leaf.__init__(self)
self.attributes["expr"] = ""
+ self.attributes["mark"] = ""
self.expr = None
def shallowCopy(self):
@@ -283,4 +333,10 @@
def getExpr(self):
return self.expr
+ def getMark(self):
+ return self.getAttribute('mark')
+
+ def setMark(self, value):
+ self.setAttribute('mark', value)
+
# vim:set ts=4 sw=4 si et sta sts=4:
Modified: waska/trunk/waskaweb/model/datapage.py
===================================================================
--- waska/trunk/waskaweb/model/datapage.py 2009-11-13 11:20:06 UTC (rev 684)
+++ waska/trunk/waskaweb/model/datapage.py 2009-11-13 11:22:00 UTC (rev 685)
@@ -213,6 +213,11 @@
# find all rules that depend on variables to be set.
# build up a lookup var-name -> list of rules
for r in document.findAllByClass(RuleLeaf):
+ mark = r.getMark()
+ # warning rules are evaluated at page rendering
+ if mark and mark.find("warning:") >= 0 or mark.find("notice:") >= 0:
+ #print "Ignore warning rule '%s'" % r.getName()
+ continue
expr = r.getExpr()
if not expr: continue
for var in expr.getDependencies():
@@ -232,7 +237,7 @@
if dependency == k: # ignore because this comes from the web
continue
# XXX: Normally they are distributed over all kind of pages.
- value = ds.getValue(dependency)
+ value = self.getData(dependency)
if value is None: isNull = True; break
vars[dependency] = value
if isNull:
Modified: waska/trunk/waskaweb/model/io/document.py
===================================================================
--- waska/trunk/waskaweb/model/io/document.py 2009-11-13 11:20:06 UTC (rev 684)
+++ waska/trunk/waskaweb/model/io/document.py 2009-11-13 11:22:00 UTC (rev 685)
@@ -51,6 +51,7 @@
DATE_TAG = u"date"
TEXT_AREA_TAG = u"textarea"
RULE_TAG = u"rule"
+CONDITIONAL_TAG = u"conditional"
namesToClasses = {
DOCUMENT_TAG: RootNode,
@@ -65,7 +66,8 @@
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,7 +82,8 @@
TEXT_AREA_TAG: SimpleCreator(NodeComponentFactory, TextAreaLeaf),
TEXT_TAG: SimpleCreator(NodeComponentFactory, TextLeaf),
RULE_TAG: SimpleCreator(NodeComponentFactory, RuleLeaf),
- DATE_TAG: SimpleCreator(NodeComponentFactory, DateLeaf)}
+ DATE_TAG: SimpleCreator(NodeComponentFactory, DateLeaf),
+ CONDITIONAL_TAG: SimpleCreator(NodeFactory, ConditionalNode)}
classesToTagNames = {
RootNode: DOCUMENT_TAG,
@@ -95,7 +98,8 @@
DateLeaf: DATE_TAG,
ExternalChoiceListLeaf: EXT_CHOICE_LIST_TAG,
RuleLeaf: RULE_TAG,
- BoolLeaf: BOOL_TAG }
+ BoolLeaf: BOOL_TAG,
+ ConditionalNode: CONDITIONAL_TAG}
def openDocument(path):
builder = SAXBuilder()
More information about the Mpuls-commits
mailing list