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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 18 09:45:26 CET 2011


Author: torsten
Date: 2011-11-18 09:45:25 +0100 (Fri, 18 Nov 2011)
New Revision: 5599

Modified:
   base/trunk/mpulsweb/model/case.py
Log:
Add setting the maximum phase after import if changemode is not manual. Note
the this may cause performance issues on large imports as setting the phase
triggers two DB-Querys.


Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2011-11-17 21:41:23 UTC (rev 5598)
+++ base/trunk/mpulsweb/model/case.py	2011-11-18 08:45:25 UTC (rev 5599)
@@ -1546,13 +1546,25 @@
                                                             e.set_data_errors))
             raise
 
-        # Trigger the tagging of the newly imported data sets.
-        #
         # We should only get here if there were no errors during import.
         # If there were any errors, an XMLImportException will have been
-        # raised and the DB changes will have been rolled back and no
-        # tagging will be necessary anyway.
-        g.case.check_validity_for_ids(self.imported_ids)
+        # raised and the DB changes will have been rolled back and no further
+        # handling of the imported cases will be necessary anyway.
+        changemode = g.mpuls_config.get('phases', 'changemode')
+        if changemode != PC_MANUAL: 
+            # Trigger setting max phase after importing when changemode is not
+            # manual. This may be not to performant many cases are important as
+            # each case needs to be loaded two time to set the phase. First
+            # time to load the phasemodel second time to load the case.
+            for case_id in self.imported_ids:
+                phases = PhaseFactory().load(case_id)
+                reachable_phase = phases.get_max_phase_id()
+                case = g.case_factory.loadById(case_id)
+                # Setting the phase includes tagging of the case.
+                case.setPhase(reachable_phase)
+        else:
+            # Trigger the tagging of the newly imported data sets.
+            g.case.check_validity_for_ids(self.imported_ids)
 
     def format_errors(self, uuid, error_items):
         out = []



More information about the Mpuls-commits mailing list