[Mpuls-commits] r398 - in wasko/trunk: . waskaweb/controllers waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Mar 18 13:37:13 CET 2009


Author: teichmann
Date: 2009-03-18 13:37:11 +0100 (Wed, 18 Mar 2009)
New Revision: 398

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/controllers/caselifetime.py
   wasko/trunk/waskaweb/model/datapage.py
Log:
Added code to extract data from a case.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-18 11:57:31 UTC (rev 397)
+++ wasko/trunk/ChangeLog.txt	2009-03-18 12:37:11 UTC (rev 398)
@@ -1,5 +1,13 @@
 2009-03-18	Sascha L. Teichmann <teichmann at intevation.de>
 
+	* waskaweb/model/datapage.py: New class DataExtractor to extract
+	  data from a case.
+
+	* waskaweb/controllers/caselifetime.py: added function to extract
+	  data from current case and filter of some black listed fields.
+
+2009-03-18	Sascha L. Teichmann <teichmann at intevation.de>
+
 	* waskaweb/model/data.py: forgot isInvisible/setInvisible methods.
 
 	* waskaweb/controllers/CaseBase.py: construct FormDataImpl with

Modified: wasko/trunk/waskaweb/controllers/caselifetime.py
===================================================================
--- wasko/trunk/waskaweb/controllers/caselifetime.py	2009-03-18 11:57:31 UTC (rev 397)
+++ wasko/trunk/waskaweb/controllers/caselifetime.py	2009-03-18 12:37:11 UTC (rev 398)
@@ -11,7 +11,10 @@
 from waskaweb.model.casedocument import DataSaveException
 from waskaweb.lib.validators import ExtraTimeFormValidator1, ExtraTimeFormValidator2, ReopenFormValidator1, ReopenFormValidator2, RenewFormValidator
 
+from waskaweb.model.datapage import DataExtractor
+from waskaweb.model.data     import WidgetCollector
 
+
 log = logging.getLogger(__name__)
 
 REOPENOK_HEADER_CONFIRM    = u"Fall wiederaufnehmen?"
@@ -49,70 +52,96 @@
     logbook.addEntry(entry)
     logbook.store(session['USER_AUTHORIZED'].id)
 
+# items not to be copied from old case
+COPY_BLACK_LIST = frozenset(['erstgespraech', 'datum_cm_beginn'])
+
+def extract_data_from_case(case_id = None):
+
+    phase_a = g.formedTree.findbyName('phase-a')
+    phase_b = g.formedTree.findbyName('phase-b')
+
+    collector = WidgetCollector()
+
+    phase_a.visit(collector.visitor)
+    phase_b.visit(collector.visitor)
+
+    keys = [w.getName() for w in collector.widgets \
+        if w.getName() not in COPY_BLACK_LIST]
+
+    extractor = DataExtractor()
+
+    if case_id is None: case_id = session['case'].id
+
+    extractor.loadData(case_id, keys)
+
+    return extractor 
+
 def checkcase():
 
-        end_art = g.formedTree.getData('cm_end_art')
-        c.casedata = g.formedTree 
-        c.phase = g.formedTree.getData('phase')
-        c.phase = 3
+    D = g.formedTree.getData
 
-        # Welche Beendigung?
-        c.erfolgreiche_reintegration = False
-        c.sonstige_beendigung = False
-        if end_art == 1:
-            c.erfolgreiche_reintegration = True
-        elif end_art == 2:
-            c.sonstige_beendigung = True
+    end_art = D('cm_end_art')
+    c.casedata = g.formedTree 
+    c.phase = D('phase')
+    c.phase = 3
 
-        # Wieviele Wiederholungen?
-        if g.formedTree.getData('cm_wiederauf_genehm_2') in (1,):
-            c.num_wiederaufnahme = 2
-        elif g.formedTree.getData('cm_wiederauf_genehm_1') in (1,):
-            c.num_wiederaufnahme = 1
-        else:
-            c.num_wiederaufnahme = 0
+    # Welche Beendigung?
+    c.erfolgreiche_reintegration = False
+    c.sonstige_beendigung = False
+    if end_art == 1:
+        c.erfolgreiche_reintegration = True
+    elif end_art == 2:
+        c.sonstige_beendigung = True
 
-        # Wieviele Verlängerungen?
-        if g.formedTree.getData('cm_datum_verlaengerung_2'):
-            c.num_verlaengerung = 2
-        elif g.formedTree.getData('cm_datum_verlaengerung_1'):
-            c.num_verlaengerung = 1
-        else:
-            c.num_verlaengerung = 0
+    # Wieviele Wiederholungen?
+    if D('cm_wiederauf_genehm_2') in (1,):
+        c.num_wiederaufnahme = 2
+    elif D('cm_wiederauf_genehm_1') in (1,):
+        c.num_wiederaufnahme = 1
+    else:
+        c.num_wiederaufnahme = 0
 
-        # Wurde Wiederaufnahme abgelehnt? -> alle Optionen ausblenden
-        if (g.formedTree.getData('cm_wiederauf_genehm_1') in (0,) \
-            or g.formedTree.getData('cm_wiederauf_genehm_2') in (0,)):
-            c.disable_all = True
-        else:
-            c.disable_all = False
+    # Wieviele Verlängerungen?
+    if D('cm_datum_verlaengerung_2'):
+        c.num_verlaengerung = 2
+    elif D('cm_datum_verlaengerung_1'):
+        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,)):
+        c.disable_all = True
+    else:
+        c.disable_all = False
 
-        # Verlängerung anzeigen 
-        if not c.disable_all and c.phase in (-1,0,2) and c.num_verlaengerung < 2:
-            c.show_verlaengerung = True
-        else: 
-            c.show_verlaengerung = False
 
-        # Wiedervorlage anzeigen
-        if not c.disable_all and c.phase in (-1,0,3,4,5) and (c.erfolgreiche_reintegration or c.phase in (-1,0)) and c.num_wiederaufnahme < 2:
-            c.show_wiedervorlage = True
-        else:
-            c.show_wiedervorlage = False
+    # Verlängerung anzeigen 
+    if not c.disable_all and c.phase in (-1,0,2) and c.num_verlaengerung < 2:
+        c.show_verlaengerung = True
+    else: 
+        c.show_verlaengerung = False
 
-        # Neuaufnahme anzeigen
-        if not c.disable_all and c.phase in (-1,0,3,4,5) and (c.sonstige_beendigung or c.phase in (-1,0)) and c.num_wiederaufnahme < 2:
-            c.show_neuaufnahme = True
-        else:
-            c.show_neuaufnahme = False 
+    # Wiedervorlage anzeigen
+    if not c.disable_all and c.phase in (-1,0,3,4,5) and (c.erfolgreiche_reintegration or c.phase in (-1,0)) and c.num_wiederaufnahme < 2:
+        c.show_wiedervorlage = True
+    else:
+        c.show_wiedervorlage = False
 
-        # Abbruch anzeigen
-        if not c.disable_all and c.phase in (-1,0,1):
-            c.show_abort = True
-        else:
-            c.show_abort = False 
+    # Neuaufnahme anzeigen
+    if not c.disable_all and c.phase in (-1,0,3,4,5) and (c.sonstige_beendigung or c.phase in (-1,0)) and c.num_wiederaufnahme < 2:
+        c.show_neuaufnahme = True
+    else:
+        c.show_neuaufnahme = False 
 
+    # Abbruch anzeigen
+    if not c.disable_all and c.phase in (-1,0,1):
+        c.show_abort = True
+    else:
+        c.show_abort = False 
 
+
 class CaselifetimeController(CasebaseController):
 
     def index(self, id=None):

Modified: wasko/trunk/waskaweb/model/datapage.py
===================================================================
--- wasko/trunk/waskaweb/model/datapage.py	2009-03-18 11:57:31 UTC (rev 397)
+++ wasko/trunk/waskaweb/model/datapage.py	2009-03-18 12:37:11 UTC (rev 398)
@@ -295,4 +295,39 @@
     def _fetchData(self):
         pass
 
+class DataExtractor(object):
+
+    def __init__(self):
+        self.data = None
+
+    def loadData(self, ds_id, keys):
+        cur, con = None, None
+
+        try:
+            con = db.getConnection()
+            cur = con.cursor()
+            select = "SELECT %s FROM master_tbl_view WHERE id = %%(ds_id)" % \
+                ", ".join(keys)
+            cur.execute(select, { 'ds_id': ds_id })
+            row = cur.fetchone()
+            if not row:
+                raise Exception("No such data set: %d" % ds_id)
+
+            self.data = dict(zip([d[0] for d in cur.description], row))
+        finally:
+            db.recycleConnection(con, cur)
+
+    def storeData(self, ds_id):
+
+        update = "UPDATE master_tbl_view SET %s WHERE id = %%(ds_id)s" % \
+          ", ".join(["%s = %%(%s)s" % (n, n) for n in self.data.iterkeys()])
+
+        try:
+            con = db.getConnection()
+            cur = con.cursor()
+            cur.execute(update, { 'ds_id': ds_id })
+            con.commit()
+        finally:
+            db.recycleConnection(con, cur)
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list