[Mpuls-commits] r3666 - base/trunk/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Sep 16 12:00:36 CEST 2010


Author: torsten
Date: 2010-09-16 12:00:34 +0200 (Thu, 16 Sep 2010)
New Revision: 3666

Modified:
   base/trunk/mpulsweb/model/case.py
Log:
* mpulsweb/model/case.py (get_unknown_value): Fixed unknown value 
* mpulsweb/model/case.py (MpulsCase.make_anonymizable): Only end phase
id make_consistent does not fail
* mpulsweb/model/case.py (MpulsCase.make_consistent): Added optional
parameter "endphase" to define the phase up to which the case will be
made consistent.


Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2010-09-16 09:30:07 UTC (rev 3665)
+++ base/trunk/mpulsweb/model/case.py	2010-09-16 10:00:34 UTC (rev 3666)
@@ -135,7 +135,7 @@
     if isinstance(meta, DateLeaf):
         value = 'unbekannt'
     elif isinstance(meta, IntLeaf):
-       value = '-999999'
+       value = '-9999999'
     elif isinstance(meta, TextLeaf):
        value = 'unbekannt'
     elif isinstance(meta, ChoiceNode):
@@ -759,19 +759,23 @@
                 raise ConsistenceCheckException(
                             h.literal(MARKANONYMIZE_FAILED_RUNNING_PHASE % desc))
 
-    def make_consistent(self):
+    def make_consistent(self, endphase=None):
         """Will ensure that the case is in a (minimal) consistent state. That
-        means that all missing required fields up to the current phase are set
-        to 'unknown'.  Missing relevant datefields (start, end) are set to the
-        current date.
+        means that all missing required fields up to the given or current phase
+        are set to 'unknown'.  Missing relevant datefields (start, end) are set
+        to the current date.
         """
         phaseslist = self.get_phaseslist()
         curphase = phaseslist.get_current_phase_id()
         data = {}
         for phase in phaseslist:
             start, end = phase.getStart(), phase.getEnd()
-            if start.id > curphase:
-                break
+            if endphase is not None:
+                if int(start.id) > int(endphase):
+                    break
+            else:
+                if int(start.id) > int(curphase):
+                    break
 
             # set relevant start and enddate to the current date if not already
             # set
@@ -788,11 +792,11 @@
                 item = self.get_formed_item(field.name)
                 try:
                     value = item.getValue()
-                    log.debug('Current value of %s: %s' % (field.id, value))
+                    #log.debug('Current value of %s: %s' % (field.id, value))
                     if value in [-1, "-1", None, ""]:
                         def_value = get_unknown_value(item)
                         if def_value:
-                            log.debug("Setting %s to %s" % (field.id, def_value))
+                            #log.debug("Setting %s to %s" % (field.id, def_value))
                             data["%s" % (field.id)] = def_value
                 except:
                     log.warning('Ups! Tried to get Value from %s which seems to be no field' 
@@ -802,11 +806,11 @@
                 try:
                     item = self.get_formed_item(field.name)
                     value = item.getValue()
-                    log.debug('Current value of %s: %s' % (field.id, value))
+                    #log.debug('Current value of %s: %s' % (field.id, value))
                     if item.getValue() in [-1, "-1", None, ""]:
                         def_value = get_unknown_value(item)
                         if def_value:
-                            log.debug("Setting %s to %s" % (field.id, def_value))
+                            #log.debug("Setting %s to %s" % (field.id, def_value))
                             data["%s" % (field.id)] = def_value
                 except:
                     log.warning('Ups! Tried to get Value from %s which seems to be no field' 
@@ -823,16 +827,15 @@
         self._load_formed_instance_tree()
         data = {}
 
+        end_phase = determineAnonymizedCaseEndPhase(self)
+        # Ensurse consistence of the case
+        self.make_consistent(end_phase)
         # Check if the current phase is already finished. If not then set to
         # finished
-        end_phase = determineAnonymizedCaseEndPhase(self)
         data['%s:%s' % (PHASEFIELD, self.id)] = str(end_phase)
         self.formed_instance.setData(data)
         self.formed_instance.commit()
 
-        # Ensurse consistence of the case
-        self.make_consistent()
-
     def getState(self):
         return self.state
 



More information about the Mpuls-commits mailing list