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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 17 12:18:02 CET 2009


Author: teichmann
Date: 2009-03-17 12:18:00 +0100 (Tue, 17 Mar 2009)
New Revision: 378

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/model/casedocument.py
Log:
Do simulation of changes if values in case formed document apply to rules.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-17 10:52:03 UTC (rev 377)
+++ wasko/trunk/ChangeLog.txt	2009-03-17 11:18:00 UTC (rev 378)
@@ -1,5 +1,10 @@
 2009-03-17	Sascha L. Teichmann	<teichmann at intevation.de>
 
+	* waskaweb/model/casedocument.py: Do simulation and raise exceptions
+	  if rules are violated. TODO write back changes.
+
+2009-03-17	Sascha L. Teichmann	<teichmann at intevation.de>
+
 	* waskaweb/model/datapage.py: Used cached rules from casedocument.
 
 	* waskaweb/model/casedocument.py: Do type conversion. TODO: simulate to

Modified: wasko/trunk/waskaweb/model/casedocument.py
===================================================================
--- wasko/trunk/waskaweb/model/casedocument.py	2009-03-17 10:52:03 UTC (rev 377)
+++ wasko/trunk/waskaweb/model/casedocument.py	2009-03-17 11:18:00 UTC (rev 378)
@@ -311,11 +311,6 @@
         return okay
 
     def setData(self, params, ds_id = None):
-        if ds_id is None:
-            case = session.get('case')
-            if not case: return None
-            ds_id = case.id
-
         # assign params to their pages
         param_pages = {}
 
@@ -359,7 +354,60 @@
             raise DataSaveException(
                 "Konnte Daten nicht konvertieren", not_converted)
 
-        # second step simulate to apply the data
+        # second step: simulate to apply the data
+        if ds_id is None:
+            case = session.get('case')
+            if not case: return None
+            ds_id = case.id
 
+        for page_name, params in param_pages.iteritems():
+            params, delete_vars = params
+            #ps = self.getPageStore(page_name, ds_id)
+            simulation = dict([(n, None) for n in delete_vars])
 
+            def getValue(n):
+                try:
+                    return simulation[n]
+                except KeyError:
+                    return self.getData(n)
+
+            for k, v in params.iteritems():
+                try:
+                    rules = self.var2rules[k]
+                except KeyError: # no rules
+                    simulation[k] = v
+                    continue
+
+                for rule in rules:
+                    mark = r.getMark()
+                    if mark and mark.find("warning:") >= 0 or mark.find("notice:") >= 0:
+                        continue
+                    expr = r.getExpr()
+                    if not expr: continue
+                    vars = {}
+                    isNull = False
+                    for dep in expr.getDependencies():
+                        if dep != k: 
+                            v = getValue(k)
+                            if v is None: isNull = True; break
+                            vars[dep] = v
+                    if isNull:
+                        simulation[k] = v
+                    else:
+                        vars[k] = v
+                        try:
+                            okay = expr.evaluate(vars)
+                        except:
+                            okay = False
+                        if not okay:
+                            not_converted.append((k, rule.getValue()))
+                        else:
+                            simulation[k] = v
+
+        if not_converted:
+            raise DataSaveException(
+                "Datenkonsistenz nicht eingehalten", not_converted)
+
+
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :



More information about the Mpuls-commits mailing list