[Formed-commits] r342 - in trunk: . formed/formed/model formed/formed/plugins/modify
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 17 16:22:18 CET 2009
Author: teichmann
Date: 2009-11-17 16:22:18 +0100 (Tue, 17 Nov 2009)
New Revision: 342
Modified:
trunk/ChangeLog
trunk/formed/formed/model/exprtree.py
trunk/formed/formed/plugins/modify/rules.py
Log:
Generate '%' (for all) variables in rule generator plug in.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-11-13 16:27:49 UTC (rev 341)
+++ trunk/ChangeLog 2009-11-17 15:22:18 UTC (rev 342)
@@ -1,3 +1,11 @@
+2009-11-17 Sascha L. Teichmann <teichmann at intevation.de>
+
+ * formed/formed/model/exprtree.py: Recognize '%' vars
+ in compilation. Does not eval it!
+
+ * formed/formed/plugins/modify/rules.py: Generate '%' vars
+ for variables in repeat groups.
+
2009-11-13 Sascha L. Teichmann <teichmann at intevation.de>
* formed/formed/plugins/export/typemap.py: Fixed to work
Modified: trunk/formed/formed/model/exprtree.py
===================================================================
--- trunk/formed/formed/model/exprtree.py 2009-11-13 16:27:49 UTC (rev 341)
+++ trunk/formed/formed/model/exprtree.py 2009-11-17 15:22:18 UTC (rev 342)
@@ -41,7 +41,7 @@
FLT_RE = re.compile(r'^([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)$')
INT_RE = re.compile(r'^([-+]?[0-9]+)$')
-VAR_RE = re.compile(r'^\$(\w+)$')
+VAR_RE = re.compile(r'^\$|%(\w+)$')
from shlex import split as lexsplit
Modified: trunk/formed/formed/plugins/modify/rules.py
===================================================================
--- trunk/formed/formed/plugins/modify/rules.py 2009-11-13 16:27:49 UTC (rev 341)
+++ trunk/formed/formed/plugins/modify/rules.py 2009-11-17 15:22:18 UTC (rev 342)
@@ -25,10 +25,10 @@
u"'%(a)s' muss vor '%(b)s' liegen."
DATE_RULE_EXPR = \
-u"$%(a)s isset $%(a)s known and $%(b)s isset $%(b)s known and and $%(a)s $%(b)s > and not"
+u"%(a)s isset %(a)s known and %(b)s isset %(b)s known and and %(a)s %(b)s > and not"
IN_PAST_EXPR = \
-u"$%(a)s isset $%(a)s known and $%(a)s today > and not"
+u"%(a)s isset %(a)s known and %(a)s today > and not"
IN_PAST_VALUE = \
u"'%(a_desc)s' darf nicht in der Zukunft liegen."
@@ -37,7 +37,7 @@
"'%(a)s' muss in der Vergangenheit liegen."
IN_FUTURE_EXPR = \
-u"$%(a)s isset $%(a)s known and today $%(a)s > and not"
+u"%(a)s isset %(a)s known and today %(a)s > and not"
IN_FUTURE_DESC = \
u"'%(a)s muss in der Zukunft liegen.'"
@@ -45,6 +45,34 @@
IN_FUTURE_VALUE = \
u"'%(a_desc)s' darf nicht in der Vergangenheit liegen."
+
+class VariableType(object):
+
+ def __init__(self, formed, mode = None, parentModes = None):
+ self.formed = formed
+ self.mode = mode
+ self.parentModes = parentModes
+ self.entities = {}
+
+ def substitute(self, name):
+ try:
+ return self.entities[name]
+ except KeyError:
+ nc = self.formed.getNodeComponentByName(name)
+ if not nc:
+ print >> sys.stderr, "WARNING: node '%s' not found."
+ value = "$%s" % name
+ else:
+ is_repeat = False
+ while nc:
+ if isinstance(nc, data.RepeatNode):
+ is_repeat = True
+ break
+ nc = nc.parent
+ value = "%s%s" % (is_repeat and "%" or "$", name)
+ self.entities[name] = value
+ return value
+
def traverse_recursive(current, graph, chain, found):
xchain = chain[:]
@@ -117,6 +145,8 @@
mode = main.getSelectedMode()
allModes = main.getAllModes()
+ var_type = VariableType(document, mode, allModes)
+
all_dates = list(document.findAllByClass(data.DateLeaf, mode, allModes))
date_graph = dict([(d.getName(), (set(), set())) for d in all_dates])
@@ -206,6 +236,7 @@
'b_desc': desc2 })
param = { 'a': pair[0], 'b': pair[1] }
rule.setDescription(DATE_RULE_DESC % param)
+ param = dict([(k, var_type.substitute(v)) for k, v in param.iteritems()])
rule.setExpr(DATE_RULE_EXPR % param)
d1.getParent().addChild(rule)
@@ -223,7 +254,7 @@
for idx, d in enumerate(today_in_past):
rule = data.RuleLeaf()
rule.setName("date-in-future-rule-%d" % idx)
- rule.setExpr(IN_FUTURE_EXPR % { 'a': d })
+ rule.setExpr(IN_FUTURE_EXPR % { 'a': var_type.substitute(d) })
rule.setDescription(IN_FUTURE_DESC % { 'a': d })
rule.setMark("error:%s" % d)
d1 = dates[d]
@@ -243,7 +274,7 @@
for idx, d in enumerate(today_in_future):
rule = data.RuleLeaf()
rule.setName("date-in-past-rule-%d" % idx)
- rule.setExpr(IN_PAST_EXPR % { 'a': d })
+ rule.setExpr(IN_PAST_EXPR % { 'a': var_type.substitute(d) })
rule.setDescription(IN_PAST_DESC % { 'a': d })
rule.setMark("error:%s" % d)
d1 = dates[d]
@@ -255,6 +286,8 @@
mode = main.getSelectedMode()
allModes = main.getAllModes()
+ var_type = VariableType(document, mode, allModes)
+
collector = data.WidgetCollector()
document.visit(collector.visitor)
widgets = collector.widgets
@@ -269,10 +302,11 @@
if w.getName() in known_fields: continue
flags = w.getFlags()
if flags.find('required') >= 0:
+ x = var_type.substitute(w.getName())
if isinstance(w, (data.ChoiceNode, data.RadioNode)):
- expr = "$%s -1 == not" % w.getName()
+ expr = "%s -1 == not" % x
else:
- expr = "$%s isset" % w.getName()
+ expr = "%s isset" % x
# create new rule
rule = data.RuleLeaf()
More information about the Formed-commits
mailing list