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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 26 16:06:34 CET 2010


Author: torsten
Date: 2010-02-26 16:06:33 +0100 (Fri, 26 Feb 2010)
New Revision: 1851

Modified:
   wasko/branches/2.0/mpulsweb/model/phase.py
Log:
Implement checking consistency on a subset of fields. Return dummy Phasepart
on get_current_phase is phase is unknown.


Modified: wasko/branches/2.0/mpulsweb/model/phase.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/phase.py	2010-02-26 15:04:59 UTC (rev 1850)
+++ wasko/branches/2.0/mpulsweb/model/phase.py	2010-02-26 15:06:33 UTC (rev 1851)
@@ -36,19 +36,20 @@
     def get_current_phase_id(self):
         '''Returns id of current active phasepart'''
         p = self.get_current_phase()
-        if p:
-            return p.id
-        else:
-            return "-1"
+        return p.id
 
     def get_current_phase(self):
-        '''Returns id of current active phasepart'''
+        '''Returns current active phasepart'''
         for phase in self:
             p1, p2 = phase.getStart(), phase.getEnd()
             if p1.is_active(): return p1
             if p2.is_active(): return p2
-        return None
 
+        # Return dummy phase for unknown phase 
+        p = EndPhasePart('-1', None, None)
+        p.phase = '-1'
+        return p
+
     def is_valid(self):
         '''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
@@ -59,15 +60,15 @@
         except ConsistenceCheckException, e:
             return False
 
-    def check_consistence(self):
+    def check_consistence(self, fields=None):
         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():
+                if not p1.is_ok(fields):
                     raise ConsistenceCheckException(CASE_NOT_CONSISTENT % phases.description)
             if p2.id <= current_phase: 
-                if not p2.is_ok(): 
+                if not p2.is_ok(fields): 
                     raise ConsistenceCheckException(CASE_NOT_CONSISTENT % phases.description)
 
 class Phase:
@@ -113,20 +114,21 @@
                         self.fields.append(Field(name, page, rules, it))
 
         # Check if the current phasepart is active
-        case_id = it.getRootNode().getIdentifier()
-        realid = "%s:%s" % (PHASEFIELD, case_id)
-        field = it.getItem(realid)
-        self.active = field.getValue() == int(self.id)
+        if it:
+            case_id = it.getRootNode().getIdentifier()
+            realid = "%s:%s" % (PHASEFIELD, case_id)
+            field = it.getItem(realid)
+            self.active = field.getValue() == int(self.id)
 
-        # Get date on which this phasepart was started
-        pdates = g.mpuls_config.get('phases', 'dates')
-        for dates in pdates:
-            for phasepart, field in dates.iteritems():          
-                if phasepart == id:
-                    log.debug(field)
-                    realid = "%s:%s" % (field, case_id)
-                    field = it.getItem(realid)
-                    self.date = field.getValue()
+            # Get date on which this phasepart was started
+            pdates = g.mpuls_config.get('phases', 'dates')
+            for dates in pdates:
+                for phasepart, field in dates.iteritems():          
+                    if phasepart == id:
+                        log.debug(field)
+                        realid = "%s:%s" % (field, case_id)
+                        field = it.getItem(realid)
+                        self.date = field.getValue()
 
     def getLinks(self):
         out = []
@@ -146,9 +148,12 @@
     def is_anonymizable(self):
         return self.id not in g.mpuls_config.get('phases', 'notanonymizable')
 
-    def is_ok(self):
+    def is_ok(self, fields=None):
         for field in self.fields:
-            if not field.is_ok(): return False
+            if not fields: # No fields provided -> checkall
+                if not field.is_ok(): return False
+            elif field.name in fields:
+                if not field.is_ok(): return False
         return True 
 
 class StartPhasePart(PhasePart):
@@ -156,7 +161,6 @@
 
 class EndPhasePart(PhasePart):
     pass
-    pass
 
 class Field:
     def __init__(self, name, page, rules, it):



More information about the Mpuls-commits mailing list