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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 24 12:32:45 CET 2009


Author: torsten
Date: 2009-03-24 12:32:36 +0100 (Tue, 24 Mar 2009)
New Revision: 425

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/controllers/case.py
   wasko/trunk/waskaweb/controllers/caselifetime.py
   wasko/trunk/waskaweb/model/casedocument.py
   wasko/trunk/waskaweb/model/datapage.py
Log:
Some cleanup in code for "neuaufnahme"


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-23 15:39:05 UTC (rev 424)
+++ wasko/trunk/ChangeLog.txt	2009-03-24 11:32:36 UTC (rev 425)
@@ -1,3 +1,11 @@
+2009-03-24	Torsten Irlaender  <torsten.irlaender at intevation.de> 
+
+	* waskaweb/model/datapage.py,
+	  waskaweb/model/casedocument.py,
+	  waskaweb/controllers/caselifetime.py,
+	  waskaweb/controllers/case.py: Some cleanup in code for
+	  "neuaufnahme". Additional fixes in pagesaving code.
+
 2009-03-23	Torsten Irlaender  <torsten.irlaender at intevation.de> 
 
 	Fixed issue93

Modified: wasko/trunk/waskaweb/controllers/case.py
===================================================================
--- wasko/trunk/waskaweb/controllers/case.py	2009-03-23 15:39:05 UTC (rev 424)
+++ wasko/trunk/waskaweb/controllers/case.py	2009-03-24 11:32:36 UTC (rev 425)
@@ -589,7 +589,7 @@
     def __save(self, pageName, params, old_errors, ds_id):
         # fetch dataset if valid
         document = g.formedTree
-        page = document.getPageStore(pageName)
+        page = document.getPageStore(pageName, int(ds_id))
         page.setId(ds_id)
         result = page.save(params, old_errors, document)
         return result, page

Modified: wasko/trunk/waskaweb/controllers/caselifetime.py
===================================================================
--- wasko/trunk/waskaweb/controllers/caselifetime.py	2009-03-23 15:39:05 UTC (rev 424)
+++ wasko/trunk/waskaweb/controllers/caselifetime.py	2009-03-24 11:32:36 UTC (rev 425)
@@ -28,6 +28,12 @@
 REOPENNOTOK_SUCCESS_HEADER    = u"Nicht genehmigte Wiederaufnahme dokumentiert."
 REOPENNOTOK_SUCCESS_TEXT      = u'Die nicht genehmigte Wiederaufnahme wurde dokumentiert. Klicken Sie auf "OK", um zur "Eingangsdokumentation" der Fallakte zu gelangen.'
 
+RENEW_2_HEADER_CONFIRM    = u"Nicht genehmigte Neuaufnahme dokumentieren?"
+RENEW_2_TEXT_CONFIRM      = u"Sie haben angegeben, das keine Genehmigung für die Neuaufnahme vorliegt! Wenn Sie fortfahren wird für diese Fallakte keine erneute Neuaufnahme mehr möglich sein."
+
+RENEW_2_SUCCESS_HEADER    = u"Nicht genehmigte Neuaufnahme dokumentiert."
+RENEW_2_SUCCESS_TEXT      = u'Die nicht genehmigte Neuaufnahme wurde dokumentiert. Klicken Sie auf "OK", um zur "Eingangsdokumentation", der Fallakte zu gelangen.'
+
 RENEW_HEADER_CONFIRM    = u"Fall neu aufnehmen?"
 RENEW_TEXT_CONFIRM      = u"Wollen Sie den Fall wirklich neu aufnehmen? Dabei wird die aktuelle Fallakte anonymisiert und relevanten Teile der Fallakte aus Phase A und Phase B in eine neue Fallakte kopiert."
 
@@ -55,18 +61,64 @@
 # items not to be copied from old case
 COPY_BLACK_LIST = frozenset(['erstgespraech', 'datum_cm_beginn'])
 
-def extract_data_from_case(case_id = None):
+def copy_case(id, ignore=None):
+    case = None
+    # copy old data. fetch all fields from PHASE A and PHASE B but ignore some
+    if not ignore: ignore = []
+    fields = extract_data_from_case(case_id=None, ignore=ignore)
+    try:
+        # create new case and store fields form the old case in the new case
+        factory = CaseFactory()
+        case = factory.createNew(data={})
+        fields.storeData(case.id)
+    except:
+        traceback.print_exc(file = sys.stderr)
+    return case
 
-    phase_a = g.formedTree.findByName('phase-a')
-    phase_b = g.formedTree.findByName('phase-b')
+def clear_abschluss(id):
+    '''Löscht die Abschlussbewertung des Falls'''
+    fields = extract_data_from_case(id)
+    fields.data['cm_end_art'] = '-1' 
+    fields.data['cm_end_verm'] = '-1' 
+    fields.data['cm_end_sonst'] = '-1'
+    fields.data['datum_cm_ende'] = None 
+    fields.storeData(id)
 
+def doc_abschluss(id):
+    fields = extract_data_from_case(id) 
+    fields.data['cm_dok_end_art'] = fields.data['cm_end_art']
+    fields.data['cm_dok_end_verm'] = fields.data['cm_end_verm']
+    fields.data['cm_dok_end_sonst'] = fields.data['cm_end_sonst']
+    fields.data['cm_dok_datum_beendigung'] = fields.data['datum_cm_ende']
+    fields.storeData(id)
+
+def save_formdata(id, data):
+    # Füge alte params aus dem Dialog in der verwaltung hinzu und schreibe alles weg
+    id = int(id)
+    sparams = session.get('lifetimeparams', {})
+    if unicode(c.casedata.getData('cm2c_t')) != 'None':
+        data['cm2c_t'] = unicode(c.casedata.getData('cm2c_t'))
+        data['cm2c_t'] += "\r\n\r\n" + sparams.get('anmerkungen', '')
+    else:
+        data['cm2c_t'] = sparams.get('anmerkungen', '')
+    del sparams['anmerkungen']
+    data.update(sparams)
+    c.casedata.setData(params=data, ds_id=id)
+
+def extract_data_from_case(case_id = None, ignore = COPY_BLACK_LIST):
+
+    phase_ee = g.formedTree.findByName('ee')
+    phase_a  = g.formedTree.findByName('phase-a')
+    phase_b  = g.formedTree.findByName('phase-b')
+
     collector = WidgetCollector()
 
+    phase_ee.visit(collector.visitor)
     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]
+        if w.getName() not in ignore]
 
     extractor = DataExtractor()
 
@@ -229,72 +281,81 @@
         c.form_result = form_result
         return render('/caselifetime/overview.mako')
 
-    def renew(self, id, confirmed='0'):
+    def renew_ok(self, id, confirmed='0'):
         checkcase()
         c.form_navigation = self._getFormNavigation()
         if confirmed == '1':
             data = {}
-            # copy old data. fetch all fields from PHASE A and PHASE B but ignore some
-            old_fields = extract_data_from_case()
+            new_case = None
             try:
                 # create new case and store fields form the old case in the new case
-                factory = CaseFactory()
-                case = factory.createNew(data={})
-                old_fields.data['phase'] = '-1'
-                old_fields.data['cm2c'] = '1'
-                params = session.get('lifetimeparams', {})
-                old_fields.data['cm2c_t'] = params.get('anmerkungen', '')
-                old_fields.storeData(case.id)
-                create_logbook(id=case.id, header='Neuaufnahme', text='Für den Fall wurde eine Neuaufnahme des Integrationsprozess dokumentiert.')
+                new_case = copy_case(c.casedata.getData('id'))
+                doc_abschluss(new_case.id)
+                data['phase'] = '-1'
+                data['cm2c'] = '1'
+                save_formdata(new_case.id, data)
+                create_logbook(id=new_case.id, header='Neuaufnahme', text='Für den Fall wurde eine Neuaufnahme des Integrationsprozess dokumentiert.')
 
                 # markiere den alten Fall zur Anonymisierung
+                factory = CaseFactory()
                 old_case = factory.loadById(session['case'].id)
                 old_case.setState(4)
                 create_logbook(header='Neuaufnahme', text='Für den Fall wurde eine Neuaufnahme des Integrationsprozess dokumentiert.')
             except Exception, err:
-                print err
+                traceback.print_exc(file = sys.stderr)
 
             c.success_for  = RENEW_SUCCESS_HEADER 
             c.success_text = RENEW_SUCCESS_TEXT
-            c.url_ok       = h.url_for(controller="/case/select/%s" % case.id)
+            c.url_ok       = h.url_for(controller="/case/select/%s" % new_case.id)
             return render('caselifetime/dialogs/success_reopen.mako') 
         else:
             c.confirm_for = RENEW_HEADER_CONFIRM
             c.question    = RENEW_TEXT_CONFIRM
-            c.url_yes     = "/caselifetime/renew/%s/1" % session['case'].id
+            c.url_yes     = "/caselifetime/renew_ok/%s/1" % session['case'].id
             c.url_no      = "/caselifetime/index/"
             return render('caselifetime/dialogs/confirm_reopen.mako')
 
+    def renew_notok(self, id, confirmed='0'):
+        checkcase()
+        c.form_navigation = self._getFormNavigation()
+        if confirmed == '1':
+            data = {}
+            new_case = None
+            try:
+                save_formdata(id, data)
+                create_logbook(id=id, header='Neuaufnahme', text='Für den Fall wurde eine nicht genehmigte Neuaufnahme des Integrationsprozess dokumentiert.')
+
+            except Exception, err:
+                traceback.print_exc(file = sys.stderr)
+
+            c.success_for  = RENEW_2_SUCCESS_HEADER 
+            c.success_text = RENEW_2_SUCCESS_TEXT
+            c.url_ok       = h.url_for(controller="/case/select/%s" % id)
+            return render('caselifetime/dialogs/success_reopen.mako') 
+        else:
+            c.confirm_for = RENEW_2_HEADER_CONFIRM
+            c.question    = RENEW_2_TEXT_CONFIRM
+            c.url_yes     = "/caselifetime/renew_notok/%s/1" % session['case'].id
+            c.url_no      = "/caselifetime/index/"
+            return render('caselifetime/dialogs/confirm_reopen.mako')
+
     def reopen_ok(self, id, confirmed='0'):
         checkcase()
         c.form_navigation = self._getFormNavigation()
         if confirmed == '1':
             data = {}
             #copy data
-            data['cm_dok_datum_beendigung'] = dd_mm_YYYY(c.casedata.getData('datum_cm_ende'))
-            data['cm_dok_end_art'] = str(c.casedata.getData('cm_end_art'))
-            data['cm_dok_end_verm'] = str(c.casedata.getData('cm_end_verm'))
+            doc_abschluss(id)
             #lösche alte abschlussbewertung und setze phase
             if c.num_wiederaufnahme < 1:
-                data['cm_end_verm'] = '-1' 
-                data['cm_end_art'] = '-1' 
-                data['datum_cm_ende'] = ''
-            data['phase'] = '2'
-            data['cm2c'] = '1'
+                data['phase'] = '2'
+                data['cm2c'] = '1'
             try:
                 # Füge alte params aus dem Dialog in der verwaltung hinzu und schreibe alles weg
-                params = session.get('lifetimeparams', {})
-                if unicode(c.casedata.getData('cm2c_t', '')) != 'None':
-                    data['cm2c_t'] = unicode(c.casedata.getData('cm2c_t', ''))
-                    data['cm2c_t'] += "\r\n\r\n" + params.get('anmerkungen', '')
-                else:
-                    data['cm2c_t'] = params.get('anmerkungen', '')
-                del params['anmerkungen']
-                data.update(params)
-                c.casedata.setData(data)
+                save_formdata(id, data)
                 create_logbook(header='Wiederaufnahme', text='Für den Fall wurde eine genehmigte Wiederaufnahme des Integrationsprozess dokumentiert.')
             except Exception, err:
-                print err
+                traceback.print_exc(file=sys.stderr)
             c.success_for  = REOPENOK_SUCCESS_HEADER 
             c.success_text = REOPENOK_SUCCESS_TEXT
             c.url_ok       = h.url_for(controller="/case/select_item/0")
@@ -302,7 +363,7 @@
         else:
             c.confirm_for = REOPENOK_HEADER_CONFIRM
             c.question    = REOPENOK_TEXT_CONFIRM
-            c.url_yes     = "/caselifetime/reopen_ok/%s/1" % session['case'].id
+            c.url_yes     = "/caselifetime/reopen_ok/%s/1" % id
             c.url_no      = "/caselifetime/index/"
             return render('caselifetime/dialogs/confirm_reopen.mako')
 
@@ -313,15 +374,7 @@
         if confirmed == '1':
             try:
                 # Füge alte params aus dem Dialog in der verwaltung hinzu und schreibe alles weg
-                params = session.get('lifetimeparams', {})
-                if unicode(c.casedata.getData('cm2c_t', '')) != 'None':
-                    data['cm2c_t'] = unicode(c.casedata.getData('cm2c_t', ''))
-                    data['cm2c_t'] += "\r\n\r\n" + params.get('anmerkungen', '')
-                else:
-                    data['cm2c_t'] = params.get('anmerkungen', '')
-                del params['anmerkungen']
-                data.update(params)
-                c.casedata.setData(data)
+                save_formdata(id, data)
                 create_logbook(header='Wiederaufnahme', text='Für den Fall wurde eine nicht genehmigte Wiederaufnahme des Integrationsprozess dokumentiert.')
             except Exception, err:
                 print err
@@ -334,7 +387,7 @@
         else:
             c.confirm_for = REOPENNOTOK_HEADER_CONFIRM
             c.question    = REOPENNOTOK_TEXT_CONFIRM
-            c.url_yes     = "/caselifetime/reopen_notok/%s/1" % session['case'].id
+            c.url_yes     = "/caselifetime/reopen_notok/%s/1" % id
             c.url_no      = "/caselifetime/index/"
             return render('caselifetime/dialogs/confirm_reopen.mako')
 
@@ -355,16 +408,10 @@
             session.save()
             try:
                 c.casedata.setData(form_result, do_write=False)
-                if c.num_wiederaufnahme < 1:
-                    if form_result.get('cm_wiederauf_genehm_1') == '1':
-                        return self.reopen_ok(0)
-                    else:
-                        return self.reopen_notok(0)
+                if form_result.get('cm_wiederauf_genehm_1') == '1' or form_result.get('cm_wiederauf_genehm_2') == '1':
+                    return self.reopen_ok(session['case'].id)
                 else:
-                    if form_result.get('cm_wiederauf_genehm_2') == '1':
-                        return self.reopen_ok(0)
-                    else:
-                        return self.reopen_notok(0)
+                    return self.reopen_notok(session['case'].id)
             except DataSaveException, err:
                 form_result_1, form_errors = err.toErrorDicts()
         except formencode.Invalid, error:
@@ -387,24 +434,12 @@
             form_result = validator.to_python(request.params)
             session['lifetimeparams'] = form_result
             session.save()
-            form_result['cm_dok_end_art'] = '2'
-            form_result['cm_dok_end_sonst'] = str(c.casedata.getData('cm_end_sonst', '-1'))
-            form_result['cm_dok_datum_beendigung'] = dd_mm_YYYY(c.casedata.getData('datum_cm_ende'))
-            if unicode(c.casedata.getData('cm2c_t', '')) != 'None':
-                form_result['cm2c_t'] = unicode(c.casedata.getData('cm2c_t', ''))
-                form_result['cm2c_t'] += "\r\n\r\n" + form_result.get('anmerkungen', '')
-            else:
-                form_result['cm2c_t'] = form_result.get('anmerkungen', '')
             try:
-                c.casedata.setData(form_result)
+                c.casedata.setData(form_result, do_write = False)
                 if form_result.get('cm_neuauf_genehm') == '1':
-                    try:
-                        c.casedata.setData(form_result, do_write = False)
-                        return self.renew(0)
-                    except DataSaveException, err:
-                        form_result_1, form_errors = err.toErrorDicts()
+                    return self.renew_ok(0)
                 else:
-                    create_logbook(header='Neuaufnahme', text='Für den Fall wurde eine nicht genehmigte Neuaufnahme des Integrationsprozess dokumentiert.')
+                    return self.renew_notok(session['case'].id)
             except DataSaveException, err:
                 form_result_1, form_errors = err.toErrorDicts()
 

Modified: wasko/trunk/waskaweb/model/casedocument.py
===================================================================
--- wasko/trunk/waskaweb/model/casedocument.py	2009-03-23 15:39:05 UTC (rev 424)
+++ wasko/trunk/waskaweb/model/casedocument.py	2009-03-24 11:32:36 UTC (rev 425)
@@ -62,14 +62,14 @@
     def __init__(self):
         self.pages = {}
 
-    def getPageStore(self, formed, name, ds_id = None):
+    def getPageStore(self, formed, name, ds_id):
         try:
-            return self.pages[name]
+            return self.pages[name+':'+str(ds_id)]
         except KeyError:
             nc = formed.findByClassAndName(PageNode, name)
             db_view = "%s_view" % name.replace('-', '_')
             page = PageStore(db_view, nc, ds_id)
-            self.pages[name] = page
+            self.pages[name+':'+str(ds_id)] = page
             return page
 
 class DataSaveException(Exception):
@@ -187,7 +187,7 @@
     def getRulesForVariable(self, var):
         return self.var2rules.get(var)
 
-    def getPageStore(self, name, ds_id=None, no_data=False):
+    def getPageStore(self, name, ds_id, no_data=False):
 
         if no_data: # XXX: urcan mode!
             db_view = "%s_view" % name.replace('-', '_')

Modified: wasko/trunk/waskaweb/model/datapage.py
===================================================================
--- wasko/trunk/waskaweb/model/datapage.py	2009-03-23 15:39:05 UTC (rev 424)
+++ wasko/trunk/waskaweb/model/datapage.py	2009-03-24 11:32:36 UTC (rev 425)
@@ -42,13 +42,14 @@
 
 class PageStore:
     #def __init__(self, relation, widgets, id = None):
-    def __init__(self, relation, nc, id = None):
+    def __init__(self, relation, nc, id):
         self.nc        = nc
         self.items     = None
         self.widgets   = None
         self.data      = None
         self.relation  = relation.replace('-', '_')
-        self.id        = id
+        print >> sys.stderr, type(id)
+        self.id        = int(id)
 
     def getWidget(self):
         return self.nc



More information about the Mpuls-commits mailing list