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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 26 09:15:02 CET 2010


Author: torsten
Date: 2010-02-26 09:15:01 +0100 (Fri, 26 Feb 2010)
New Revision: 1830

Modified:
   wasko/branches/2.0/mpulsweb/model/phase.py
Log:
* mpulsweb/model/phase.py (ConsistenceCheckException): Moved exception
class into phase model
* mpulsweb/model/phase.py (PhaseList.check_consistence): New Method.
Raises exception with info on which phase is not consistent.
* mpulsweb/model/phase.py (PhaseList.is_valid): Use check_consistence
to estimate consistence of a case.


Modified: wasko/branches/2.0/mpulsweb/model/phase.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/phase.py	2010-02-26 07:48:14 UTC (rev 1829)
+++ wasko/branches/2.0/mpulsweb/model/phase.py	2010-02-26 08:15:01 UTC (rev 1830)
@@ -10,6 +10,12 @@
 
 log = logging.getLogger(__name__)
 
+CASE_NOT_CONSISTENT = "At least the phase '%s' is not in a consistent state and seems to have some missing required fields."
+
+class ConsistenceCheckException(Exception):
+    def __init__(self, value):
+        self.value = value
+
 class PhaseFactory:
 
     def __init__(self):
@@ -39,14 +45,22 @@
         '''Returns true if all phaseparts up to the current phase are ok. This
         means all requierd fields are filled out and all checks for rules are
         ok. Else return False'''
+        try:
+            self.check_consistence()
+            return True
+        except:
+            return False
+
+    def check_consistence(self):
         current_phase = self.get_current_phase_id()
         for phases in self:
             p1, p2 = phases.getStart(), phases.getEnd()
             if p1.id <= current_phase: 
-                if not p1.is_ok(): return False
+                if not p1.is_ok():
+                    raise ConsistenceCheckException(CASE_NOT_CONSISTENT % phases.description)
             if p2.id <= current_phase: 
-                if not p2.is_ok(): return False
-        return True
+                if not p2.is_ok(): 
+                    raise ConsistenceCheckException(CASE_NOT_CONSISTENT % phases.description)
 
 class Phase:
 



More information about the Mpuls-commits mailing list