[Mpuls-commits] r2326 - wasko/branches/2.0/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 13 16:59:07 CEST 2010


Author: torsten
Date: 2010-04-13 16:59:07 +0200 (Tue, 13 Apr 2010)
New Revision: 2326

Modified:
   wasko/branches/2.0/mpulsweb/model/phase.py
Log:
New is ok_method. Added method to check if two phases are neighbored.


Modified: wasko/branches/2.0/mpulsweb/model/phase.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/phase.py	2010-04-13 14:58:04 UTC (rev 2325)
+++ wasko/branches/2.0/mpulsweb/model/phase.py	2010-04-13 14:59:07 UTC (rev 2326)
@@ -145,6 +145,7 @@
 
     def __init__(self, id, phase, it):
         self.id = id
+        self.it = it
         self.phase = phase
         self.active = False
         self.date = None
@@ -197,7 +198,37 @@
     def is_anonymizable(self):
         return self.id not in g.mpuls_config.get('phases', 'notanonymizable')
 
+    def is_neighbor(self, phase):
+        suc = False
+        pre = False
+        phase = int(phase)
+        cphase = int(self.phase)
+        for p, s in g.mpuls_config.get('phases', 'successors')[0].iteritems():
+            s = [int(id) for id in s]
+            p = int(p)
+            if p == cphase:
+                log.debug("is %s suc (%s) of %s: %s" % (phase, s, cphase, phase in s))
+                suc = phase in s
+            log.debug("%s, %s" % (cphase, s))
+            if cphase in s:
+                log.debug("is %s pre (%s) of %s: %s" % (cphase, p, s, p == phase))
+                pre = (p == phase) 
+            if pre or suc: return True
+
     def is_ok(self, fields=None):
+
+        # 1. Simulate switching the phase
+        # Setting values will trigger evaluation error rules. This way we can
+        # check logic rules which are modeled as errors.
+        case_id = self.it.getRootNode().getIdentifier()
+        realid = "%s:%s" % (PHASEFIELD, case_id)
+        try:
+            values = {realid: self.id}
+            self.it.setData(values)
+        except:
+            return False
+
+        # 2. Check rules
         for field in self.fields:
             if not fields:
                 # No fields provided -> checkall
@@ -206,6 +237,7 @@
             elif field.name in fields:
                 if not field.is_ok():
                     return False
+
         return True
 
 



More information about the Mpuls-commits mailing list