[Mpuls-commits] r3311 - base/trunk/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 3 11:14:42 CEST 2010


Author: torsten
Date: 2010-08-03 11:14:42 +0200 (Tue, 03 Aug 2010)
New Revision: 3311

Modified:
   base/trunk/mpulsweb/controllers/formularpage.py
Log:
* mpulsweb/controllers/formularpage.py (save): Depending on the
configuration try to set the maximum reachable phase after saving data
and validating the case.


Modified: base/trunk/mpulsweb/controllers/formularpage.py
===================================================================
--- base/trunk/mpulsweb/controllers/formularpage.py	2010-08-03 09:07:29 UTC (rev 3310)
+++ base/trunk/mpulsweb/controllers/formularpage.py	2010-08-03 09:14:42 UTC (rev 3311)
@@ -25,6 +25,10 @@
 from mpulsweb.lib.renderer import ViewRenderer, RepeatGroupRenderer, \
      ErrorRenderer, apply_hidden_booleans, get_child_num
 from mpulsweb.lib.helpers import url_for, dd_mm_YYYY as format_date
+from mpulsweb.model.phase import PhaseFactory, \
+     PC_MANUAL, PC_HALFAUTO, PC_FULLAUTO, \
+     DIALOG_FULLAUTOMATIC_CHANGE_TITLE, DIALOG_FULLAUTOMATIC_CHANGE_TEXT, \
+     DIALOG_HALFAUTOMATIC_CHANGE_TITLE, DIALOG_HALFAUTOMATIC_CHANGE_TEXT
 
 
 log = logging.getLogger(__name__)
@@ -228,6 +232,45 @@
             session['uncommited_fields'] = instance_tree.commit()
             session.save()
 
+        # Check requried fields of the case and set phase 
+        changemode = g.mpuls_config.get('phases', 'changemode')
+        if changemode != PC_MANUAL:
+            phases = PhaseFactory().load(session['case'].id)
+            log.debug("current phase: %s" % phases.get_current_phase_id())
+            log.debug("max phase? %s" % phases.get_max_phase_id())
+            current_phase = phases.get_current_phase_id()
+            log.debug(g.mpuls_config.get('phases', 'description'))
+            reachable_phase = phases.get_max_phase_id()
+            if current_phase != reachable_phase:
+                cpd = phases.get_phase(current_phase).getDescription() 
+                rpd = phases.get_phase(reachable_phase).getDescription() 
+                if changemode == PC_FULLAUTO:
+                    log.debug("fullautomatic phase change!")
+                    #load case and set phase
+                    case = g.case_factory.loadById(session['case'].id)
+                    case.getState().setPhase(reachable_phase)
+                    # build dialog
+                    c.dialog_title = DIALOG_FULLAUTOMATIC_CHANGE_TITLE
+                    c.dialog_text = DIALOG_FULLAUTOMATIC_CHANGE_TEXT \
+                    % (cpd, rpd)
+                    c.url_ok = url_for(controller="formularpage", 
+                                         action="select", 
+                                         id=page_id)  
+                    return render('/phase/dialogs/success_fullautomatic_set_phase.mako')
+                else:
+                    log.debug("halfautomatic phase change!")
+                    # build dialog
+                    c.dialog_title = DIALOG_HALFAUTOMATIC_CHANGE_TITLE 
+                    c.dialog_text = DIALOG_HALFAUTOMATIC_CHANGE_TEXT \
+                    % (cpd, rpd)
+                    c.url_ok = url_for(controller="phase", 
+                                         action="setPhase", 
+                                         id=session['case'].id,
+                                         value=reachable_phase)  
+                    c.url_no = url_for(controller="formularpage", 
+                                         action="select", 
+                                         id=page_id)
+                    return render('/phase/dialogs/success_halfautomatic_set_phase.mako')
         return self.select(page_id)
 
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))



More information about the Mpuls-commits mailing list