[Formed-commits] r320 - in trunk: . formed/formed/model formed/formed/plugins/modify
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Mar 20 15:40:38 CET 2009
Author: teichmann
Date: 2009-03-20 15:40:36 +0100 (Fri, 20 Mar 2009)
New Revision: 320
Modified:
trunk/ChangeLog
trunk/formed/formed/model/data.py
trunk/formed/formed/plugins/modify/rules.py
Log:
Date rules: Fixed error message. Generate past and future rules.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-03-16 14:43:03 UTC (rev 319)
+++ trunk/ChangeLog 2009-03-20 14:40:36 UTC (rev 320)
@@ -1,3 +1,10 @@
+2009-03-20 Sascha L. Teichmann <teichmann at intevation.de>
+
+ * formed/formed/model/data.py: Removed debug output
+
+ * formed/formed/plugins/modify/rules.py: Fixed error message.
+ Generate past and future rules.
+
2009-03-16 Sascha L. Teichmann <teichmann at intevation.de>
* formed/formed/model/exprtree.py: Forget to call today with context.
Modified: trunk/formed/formed/model/data.py
===================================================================
--- trunk/formed/formed/model/data.py 2009-03-16 14:43:03 UTC (rev 319)
+++ trunk/formed/formed/model/data.py 2009-03-20 14:40:36 UTC (rev 320)
@@ -37,7 +37,6 @@
return VISIT_IGNORE_CHILDREN
elif isinstance(nc, Leaf) and not isinstance(nc,
(RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
- print nc.getName()
self.widgets.append(nc)
return VISIT_CONTINUE
Modified: trunk/formed/formed/plugins/modify/rules.py
===================================================================
--- trunk/formed/formed/plugins/modify/rules.py 2009-03-16 14:43:03 UTC (rev 319)
+++ trunk/formed/formed/plugins/modify/rules.py 2009-03-20 14:40:36 UTC (rev 320)
@@ -27,7 +27,24 @@
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"
+IN_PAST_EXPR = \
+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."
+
+IN_PAST_DESC = \
+"'%(a)s' muss in der Vergangenheit liegen."
+
+IN_FUTURE_EXPR = \
+u"$%(a)s isset $%(a)s known and today $%(a)s > and not"
+
+IN_FUTURE_DESC = \
+u"'%(a)s muss in der Zukunft liegen.'"
+
+IN_FUTURE_VALUE = \
+u"'%(a_desc)s' darf nicht in der Vergangenheit liegen."
+
def traverse_recursive(current, graph, chain, found):
xchain = chain[:]
@@ -104,6 +121,9 @@
date_graph = dict([(d.getName(), (set(), set())) for d in all_dates])
+ today_in_future = set()
+ today_in_past = set()
+
for date in all_dates:
order = date.getOrder()
m = ORDER_RE.match(order)
@@ -117,6 +137,9 @@
for pred in preds.split(","):
pred = pred.strip()
if not pred: continue
+ if pred == "$TODAY":
+ today_in_past.add(name)
+ continue
try:
# add current to succs of pred
date_graph[pred][1].add(name)
@@ -128,12 +151,15 @@
for succ in succs.split(","):
succ = succ.strip()
+ if succ == "$TODAY":
+ today_in_future.add(name)
+ continue
if not succ: continue
try:
# add current to preds of succ
date_graph[succ][0].add(name)
except KeyError:
- print >> sys.stderr, "succ date '%s' not found" % pred
+ print >> sys.stderr, "succ date '%s' not found" % succ
continue
# add to succs
s_set.add(succ)
@@ -184,6 +210,46 @@
d1.getParent().addChild(rule)
+ for d in today_in_past.copy():
+ stack = [ d ]
+ while stack:
+ d = stack.pop()
+ today_in_past.add(d)
+ try:
+ stack.extend(date_graph[d][1])
+ except KeyError:
+ pass
+
+ 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.setDescription(IN_FUTURE_DESC % { 'a': d })
+ rule.setMark("error:%s" % d)
+ d1 = dates[d]
+ rule.setValue(IN_FUTURE_EXPR_VALUE % { 'a_desc': u" / ".join(descriptions(d1)) })
+ d1.getParent().addChild(rule)
+
+ for d in today_in_future.copy():
+ stack = [ d ]
+ while stack:
+ d = stack.pop()
+ today_in_future.add(d)
+ try:
+ stack.extend(date_graph[d][0])
+ except KeyError:
+ pass
+
+ 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.setDescription(IN_PAST_DESC % { 'a': d })
+ rule.setMark("error:%s" % d)
+ d1 = dates[d]
+ rule.setValue(IN_PAST_VALUE % { 'a_desc': u" / ".join(descriptions(d1)) })
+ d1.getParent().addChild(rule)
+
def generateRequiredRules(self, main):
document = main.getDocument()
mode = main.getSelectedMode()
More information about the Formed-commits
mailing list