[Mpuls-commits] r3602 - in wasko/trunk: . waskoweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 13 15:08:32 CEST 2010


Author: roland
Date: 2010-09-13 15:08:31 +0200 (Mon, 13 Sep 2010)
New Revision: 3602

Modified:
   wasko/trunk/ChangeLog
   wasko/trunk/waskoweb/controllers/formularpage.py
Log:
issue933: only create appointments when phase longer than max

Modified: wasko/trunk/ChangeLog
===================================================================
--- wasko/trunk/ChangeLog	2010-09-13 10:41:22 UTC (rev 3601)
+++ wasko/trunk/ChangeLog	2010-09-13 13:08:31 UTC (rev 3602)
@@ -1,3 +1,9 @@
+2010-09-10  Roland Geider  <roland.geider at intevation.de>
+	
+	* waskoweb/controllers/formularpage.py: issue933: only create
+	  appointments when the case management phase is longer than the
+	  limits
+
 2010-09-10  Bernhard Herzog  <bh at intevation.de>
 
 	* waskoweb/lib/search.py (CaseSearch.VALID_OPTIONS)

Modified: wasko/trunk/waskoweb/controllers/formularpage.py
===================================================================
--- wasko/trunk/waskoweb/controllers/formularpage.py	2010-09-13 10:41:22 UTC (rev 3601)
+++ wasko/trunk/waskoweb/controllers/formularpage.py	2010-09-13 13:08:31 UTC (rev 3602)
@@ -145,12 +145,13 @@
         
         NOTE: this solution is not yet optimal
         """
-        if (u'erstgespraech:%s' % case_id in form_result or
+        if (u'datum_cm_start:%s' % case_id in form_result or
+                u'datum_cm_ende:%s' % case_id in form_result or
                 u'cm_datum_verlaengerung_1:%s' % case_id in form_result or 
                 u'cm_datum_verlaengerung_2:%s' % case_id in form_result):
             conn = db.getConnection()
             cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-            cur.execute('''SELECT erstgespraech,
+            cur.execute('''SELECT datum_cm_start,
                                 datum_cm_ende,
                                 cm_datum_verlaengerung_1,
                                 cm_datum_verlaengerung_2,
@@ -163,62 +164,68 @@
             
             # log.debug('case_data: %s' % case_data)
             #max([date for date in case_data[:3] if date != None])
+            date_cm_start    = case_data[0] or datetime.date.today()
+            date_cm_end      = case_data[1] or datetime.date.today()
             date_extension_1 = case_data[2]
             date_extension_2 = case_data[3]
-            first_date = case_data[0] or datetime.date.today()
             
+            
             # Maximum of 18 months with 2 extensions
             if (date_extension_1 != None and date_extension_2 != None):
+                end_date = date_extension_2
                 max_time_delta = datetime.timedelta(18*31)
             # Maximum of 15 months with 1 extension
             elif (date_extension_1 != None and date_extension_2 == None):
+                end_date = date_extension_1
                 max_time_delta = datetime.timedelta(15*31)
             # Everything else, 12 months
             else:
+                end_date = date_cm_end
                 max_time_delta = datetime.timedelta(12*31)
             
-            appointment_factory = CaseAppointmentFactory()
-            
-            # Use the first date from the DB as it is properly validated
-            # Try first to load the existing appointment and overwrite its data
-            # if one is found
-            #
-            # Searching by name and hoping that it didn't change is... ugly
-            search_appointment_sql = u"""SELECT id
-                    FROM ka_fall_termine_tbl_view
-                    WHERE name LIKE 'Zu langer Case-Management der Fallakte %s' 
-                        AND art = 1
-                        AND master_id = %s"""  % (case_data[4], case_id)
-            
-            cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-            cur.execute(search_appointment_sql)
-            appointments = cur.fetchall()
-            
-            appointment = appointment_factory.createNew(case_id)
-            # Found appointment, update
-            if appointments:
-                appointment_id = appointments[0].pop() #ideally, we are cleverer
-                appointment = appointment_factory.loadById(appointment_id)
-            # No appointment found, new one
-            else:
+            if end_date - date_cm_start > max_time_delta:
+                appointment_factory = CaseAppointmentFactory()
+                
+                # Use the first date from the DB as it is properly validated
+                # Try first to load the existing appointment and overwrite its data
+                # if one is found
+                #
+                # Searching by name and hoping that it didn't change is... ugly
+                search_appointment_sql = u"""SELECT id
+                        FROM ka_fall_termine_tbl_view
+                        WHERE name LIKE 'Zu langer Case-Management der Fallakte %s' 
+                            AND art = 1
+                            AND master_id = %s"""  % (case_data[4], case_id)
+                
+                cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
+                cur.execute(search_appointment_sql)
+                appointments = cur.fetchall()
+                
                 appointment = appointment_factory.createNew(case_id)
+                # Found appointment, update
+                if appointments:
+                    appointment_id = appointments[0].pop() #ideally, we are cleverer
+                    appointment = appointment_factory.loadById(appointment_id)
+                # No appointment found, new one
+                else:
+                    appointment = appointment_factory.createNew(case_id)
+                
+                appointment_data = {'description': u'''Bitte überprüfen Sie die
+                eingetragenen Datumsangaben, die Fallakte %s von %s %s 
+                überschreitet die maximale Dauer der Phase Case-Management
+                von 12 Monaten.''' % (case_data[4], case_data[5], case_data[6]),
+                'title': u'Zu langer Case-Management der Fallakte %s' % case_data[4],
+                'case_id': case_id,
+                'start_time': datetime.time(00, 00),
+                'start_date': date_cm_end + max_time_delta,
+                'end_time': None,
+                'end_date': None,
+                'type': u'1', #reminder
+                'id': u''
+                }
             
-            appointment_data = {'description': u'''Bitte überprüfen Sie die
-            eingetragenen Datumsangaben, die Fallakte %s von %s %s 
-            überschreitet die maximale Dauer der Phase Case-Management
-            von 12 Monaten.''' % (case_data[4], case_data[5], case_data[6]),
-            'title': u'Zu langer Case-Management der Fallakte %s' % case_data[4],
-            'case_id': case_id,
-            'start_time': datetime.time(00, 00),
-            'start_date': first_date + max_time_delta,
-            'end_time': None,
-            'end_date': None,
-            'type': u'1', #reminder
-            'id': u''
-            }
-            
-            appointment.setData(appointment_data)
-            appointment.store()
+                appointment.setData(appointment_data)
+                appointment.store()
         
         
         """



More information about the Mpuls-commits mailing list