[Mpuls-commits] r986 - wasko/branches/2.0/waskaweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 28 17:05:48 CET 2010


Author: torsten
Date: 2010-01-28 17:05:47 +0100 (Thu, 28 Jan 2010)
New Revision: 986

Modified:
   wasko/branches/2.0/waskaweb/controllers/caselifetime.py
Log:
* waskaweb/controllers/caselifetime.py (_get_value): New.
Helperfunction to get values from the libformed. 

* waskaweb/controllers/caselifetime.py (checkcase): Use _get_value
method to get values form the libformed.

* waskaweb/controllers/caselifetime.py (CaselifetimeController.index):
Use _get_value method to get values form the libformed.


Modified: wasko/branches/2.0/waskaweb/controllers/caselifetime.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/caselifetime.py	2010-01-28 15:44:24 UTC (rev 985)
+++ wasko/branches/2.0/waskaweb/controllers/caselifetime.py	2010-01-28 16:05:47 UTC (rev 986)
@@ -22,7 +22,10 @@
 from waskaweb.model.data import WidgetCollector
 from waskaweb.controllers.CaseBase import CasebaseController
 
+from formed.instance.backends.postgres import DBFactory as InstanceFactory
+from waskaweb.lib.db import db, PostgresDBInterface
 
+
 log = logging.getLogger(__name__)
 
 
@@ -211,15 +214,24 @@
 
     return extractor
 
-def checkcase():
-    D = g.formedTree.getData
+def _get_value(it, id, case_id):
+    real_id = "%s:%s" % (id, case_id)
+    item = it.getItem(real_id)
+    if item:
+        value = item.getValue()
+        log.debug('%s = "%r"' % (real_id, value))
+        return value
+    log.error('Can not find item "%s"' % real_id)
 
-    end_art = D('cm_end_art')
-    c.casedata = g.formedTree
-    c.phase = D('phase')
-    c.cm_neuauf_genehm = D('cm_neuauf_genehm')
+def checkcase(it, id):
+    case_id = id
+    D = _get_value
 
-    # Welche Beendigung?
+    end_art = D(it, 'cm_end_art', case_id)
+    c.phase = D(it, 'phase', case_id)
+    c.cm_neuauf_genehm = D(it, 'cm_neuauf_genehm', case_id)
+
+    ## Welche Beendigung?
     c.erfolgreiche_reintegration = False
     c.sonstige_beendigung = False
     if end_art == 1:
@@ -228,24 +240,24 @@
         c.sonstige_beendigung = True
 
     # Wieviele Wiederholungen?
-    if D('cm_wiederauf_genehm_2') in (1,):
+    if D(it, 'cm_wiederauf_genehm_2', case_id) in (1,):
         c.num_wiederaufnahme = 2
-    elif D('cm_wiederauf_genehm_1') in (1,):
+    elif D(it, 'cm_wiederauf_genehm_1', case_id) in (1,):
         c.num_wiederaufnahme = 1
     else:
         c.num_wiederaufnahme = 0
 
     # Wieviele Verlängerungen?
-    if D('cm_datum_verlaengerung_2'):
+    if D(it, 'cm_datum_verlaengerung_2', case_id):
         c.num_verlaengerung = 2
-    elif D('cm_datum_verlaengerung_1'):
+    elif D(it, 'cm_datum_verlaengerung_1', case_id):
         c.num_verlaengerung = 1
     else:
         c.num_verlaengerung = 0
 
     # Wurde Wiederaufnahme abgelehnt? -> alle Optionen ausblenden
-    if (D('cm_wiederauf_genehm_1') in (0,)
-        or D('cm_wiederauf_genehm_2') in (0,)):
+    if (D(it, 'cm_wiederauf_genehm_1', case_id) in (0,)
+        or D(it, 'cm_wiederauf_genehm_2', case_id) in (0,)):
         c.disable_all = True
         c.wiederaufn_abg = True
     else:
@@ -286,22 +298,24 @@
 class CaselifetimeController(CasebaseController):
 
     def index(self, id=None):
-        # Return a rendered template
-        #   return render('/some/template.mako')
-        # or, Return a response
         c.form_errors = {}
         c.form_result = {}
-        checkcase()
+        factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+        it = factory.loadInstanceTreeByIdentifier(id)
+        case_id = it.getRootNode().getIdentifier()
+        checkcase(it, case_id)
+        D = _get_value
+
         try:
             if c.num_wiederaufnahme >= 1:
-                last_date = c.casedata.getData('cm_wiederauf_datum_bis_1')
+                last_date = D(it, 'cm_wiederauf_datum_bis_1', case_id)
                 if last_date:
                     c.form_result['cm_wiederauf_datum_bis_2'] = \
                                   dd_mm_YYYY(last_date+timedelta(days=31*3))
                 else:
                     c.form_result['cm_wiederauf_datum_bis_2'] = ''
             if c.num_verlaengerung < 1:
-                begin_cm = c.casedata.getData('datum_cm_start')
+                begin_cm = D(it, 'datum_cm_start', case_id)
                 if begin_cm:
                     c.form_result['cm_datum_verlaengerung_1'] = \
                                    dd_mm_YYYY(begin_cm+timedelta(days=458))
@@ -309,7 +323,7 @@
                     c.form_result['cm_datum_verlaengerung_1'] = ''
 
             if c.num_verlaengerung  == 1:
-                ende_verl1 = c.casedata.getData('cm_datum_verlaengerung_1')
+                ende_verl1 = D(it, 'cm_datum_verlaengerung_1', case_id)
                 if ende_verl1:
                     c.form_result['cm_datum_verlaengerung_2'] = \
                                    dd_mm_YYYY(ende_verl1+timedelta(days=31*3))



More information about the Mpuls-commits mailing list