[Mpuls-commits] r4740 - base/trunk/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 1 17:51:37 CET 2011


Author: torsten
Date: 2011-03-01 17:51:37 +0100 (Tue, 01 Mar 2011)
New Revision: 4740

Modified:
   base/trunk/mpulsweb/model/appointment.py
Log:
* mpulsweb/model/appointment.py: Issue1875: Moved modul-wide defined
	SQL statements into classes as class-attributes to make them better
	overridable.


Modified: base/trunk/mpulsweb/model/appointment.py
===================================================================
--- base/trunk/mpulsweb/model/appointment.py	2011-03-01 15:31:08 UTC (rev 4739)
+++ base/trunk/mpulsweb/model/appointment.py	2011-03-01 16:51:37 UTC (rev 4740)
@@ -38,124 +38,8 @@
 from mpulsweb.model.agencysettings import Agency
 from mpulsweb.controllers.case_overview import default_phases 
 
-
-GET_GLOBAL_APPOINTMENT_SQL = """\
-SELECT id, master_id, sdatum, edatum, name, beschreibung, art
-FROM ka_global_termine_tbl_view
-WHERE id = %(id)s
-"""
-GET_GLOBAL_APPOINTMENTLIST_SQL = """\
-SELECT id, master_id, sdatum, edatum, name, beschreibung, art
-FROM ka_global_termine_tbl_view
-WHERE coalesce(edatum, sdatum)::date+1 >= %(date)s::date ORDER BY sdatum
-"""
-DELETE_GLOBAL_APPOINTMENT_SQL = "SELECT delete_global_termin_ds(%(id)s)"
-CREATE_GLOBAL_APPOINTMENT_SQL = "SELECT create_global_termin_ds()"
-STORE_GLOBAL_APPOINTMENT_SQL = """\
-UPDATE ka_global_termine_tbl_view
-SET
-    sdatum = %(start_date)s::timestamp,
-    edatum = %(end_date)s::timestamp,
-    name = %(title)s,
-    beschreibung = %(description)s,
-    art = %(type)s
-WHERE id = %(id)s
-"""
-
-GET_CASE_APPOINTMENT_SQL = """\
-SELECT id, master_id, sdatum, edatum, name, beschreibung, art
-FROM ka_fall_termine_tbl_view
-WHERE id = %(id)s
-"""
-
-GET_CASE_APPOINTMENTLIST_SQL = """\
-SELECT id, master_id, sdatum, edatum, name, beschreibung, art
-FROM ka_fall_termine_tbl_view
-WHERE master_id = %(id)s
-      AND coalesce(edatum, sdatum)::date+1 >= %(date)s::date
-      AND art = 0
-ORDER BY sdatum
-"""
-
-GET_CASE_REMINDERLIST_SQL = """\
-SELECT id, master_id, sdatum, edatum, name, beschreibung, art
-FROM ka_fall_termine_tbl_view
-WHERE master_id = %(id)s AND art = 1
-ORDER BY sdatum
-"""
-
-GET_ALLCASES_APPOINTMENTLIST_SQL = """\
-SELECT a.id, a.master_id, a.sdatum, a.edatum, a.name, a.beschreibung, a.art
-FROM ka_fall_termine_tbl_view a 
-JOIN master_tbl_view m ON m.id = a.master_id 
-JOIN ka_status_tbl_view s ON m.id = s.master_id
-WHERE coalesce(edatum, sdatum)::date+1 >= %(date)s::date
-      AND art = 0 AND m.bearbeiter_id = %(editor)s AND s.status = 1
-ORDER BY sdatum
-"""
-
-GET_ALLCASES_REMINDERLIST_SQL = """\
-SELECT a.id, a.master_id, a.sdatum, a.edatum, a.name, a.beschreibung, a.art
-FROM ka_fall_termine_tbl_view a 
-JOIN master_tbl_view m ON m.id = a.master_id
-JOIN ka_status_tbl_view s ON m.id = s.master_id
-WHERE art = 1 AND m.bearbeiter_id = %(editor)s AND s.status = 1
-ORDER BY sdatum
-"""
-
-DELETE_CASE_APPOINTMENT_SQL = "SELECT delete_fall_termin_ds(%(id)s)"
-CREATE_CASE_APPOINTMENT_SQL = "SELECT create_fall_termin_ds(%(id)s)"
-STORE_CASE_APPOINTMENT_SQL = """\
-UPDATE ka_fall_termine_tbl_view
-SET
-    sdatum = %(start_date)s::timestamp,
-    edatum = %(end_date)s::timestamp,
-    name = %(title)s,
-    beschreibung = %(description)s,
-    art = %(type)s
-WHERE id = %(id)s
-"""
-
-GET_OLDACTIVE_CASES_4_ADMIN = """
-SELECT m.id, s.zugriff, getLastCaseAppointment(m.id) AS last_date
-FROM
-  (SELECT * FROM ka_status_tbl_view
-   WHERE zugriff < now() - interval '1 day' * %%(maxdays)s AND status <> 5) s
-   JOIN master_tbl_view m ON m.id = s.master_id
-WHERE phase in (%s)
-AND (%s)
-"""
-
-GET_OLDACTIVE_CASES = """
-SELECT m.id, s.zugriff, getLastCaseAppointment(m.id) AS last_date
-FROM
-  (SELECT * FROM ka_status_tbl_view
-   WHERE zugriff < now() - interval '1 day' * %%(maxdays)s AND status <> 5) s
-   JOIN master_tbl_view m ON m.id = s.master_id
-WHERE phase in (%s) AND (%s) AND m.bearbeiter_id = %%(editor)s
-"""
-
-GET_OLDFINISHED_CASES_4_ADMIN = """\
-SELECT m.id, s.zugriff, getLastCaseAppointment(m.id) as last_date
-FROM master_tbl_view m JOIN ka_status_tbl_view s ON s.master_id = m.id
-WHERE s.status <> 5
-      AND extract(day from now()-s.zugriff) > %%(maxdays)s
-      AND phase in (%s)
-      AND (%s)"""
-
-GET_OLDFINISHED_CASES = """\
-SELECT m.id, s.zugriff, getLastCaseAppointment(m.id) as last_date
-FROM master_tbl_view m JOIN ka_status_tbl_view s ON s.master_id = m.id
-WHERE s.status <> 5
-      AND m.bearbeiter_id = %%(editor)s
-      AND extract(day from now()-s.zugriff) > %%(maxdays)s
-      AND phase in (%s)
-      AND (%s)
-"""
-
 log = logging.getLogger(__name__)
 
-
 class AppointmentFactory:
 
     def loadById(self, id):
@@ -210,25 +94,38 @@
 
 class CaseAppointmentFactory(AppointmentFactory):
 
+    GET_CASE_APPOINTMENT_SQL = """SELECT id, master_id, sdatum, edatum, name,
+    beschreibung, art FROM ka_fall_termine_tbl_view WHERE id = %(id)s """
+    CREATE_CASE_APPOINTMENT_SQL = "SELECT create_fall_termin_ds(%(id)s)"
+
     def __init__(self):
-        self.get_sql = GET_CASE_APPOINTMENT_SQL
-        self.create_sql = CREATE_CASE_APPOINTMENT_SQL
+        self.get_sql = self.GET_CASE_APPOINTMENT_SQL
+        self.create_sql = self.CREATE_CASE_APPOINTMENT_SQL
         self.constructor = CaseAppointment
 
 
 class CaseReminderFactory(AppointmentFactory):
 
+    GET_CASE_APPOINTMENT_SQL = """SELECT id, master_id, sdatum, edatum, name,
+    beschreibung, art FROM ka_fall_termine_tbl_view WHERE id = %(id)s """
+    CREATE_CASE_APPOINTMENT_SQL = "SELECT create_fall_termin_ds(%(id)s)"
+
     def __init__(self):
-        self.get_sql = GET_CASE_APPOINTMENT_SQL
-        self.create_sql = CREATE_CASE_APPOINTMENT_SQL
+        self.get_sql = self.GET_CASE_APPOINTMENT_SQL
+        self.create_sql = self.CREATE_CASE_APPOINTMENT_SQL
         self.constructor = CaseReminder
 
 
 class GlobalAppointmentFactory(AppointmentFactory):
 
+    GET_GLOBAL_APPOINTMENT_SQL = """SELECT id, master_id, sdatum, edatum,
+    name, beschreibung, art FROM ka_global_termine_tbl_view WHERE id = %(id)s
+    """
+    CREATE_GLOBAL_APPOINTMENT_SQL = "SELECT create_global_termin_ds()"
+
     def __init__(self):
-        self.get_sql = GET_GLOBAL_APPOINTMENT_SQL
-        self.create_sql = CREATE_GLOBAL_APPOINTMENT_SQL
+        self.get_sql = self.GET_GLOBAL_APPOINTMENT_SQL
+        self.create_sql = self.CREATE_GLOBAL_APPOINTMENT_SQL
         self.constructor = GlobalAppointment
 
 
@@ -262,44 +159,70 @@
 
 class CaseAppointmentOverview(AppointmentOverview):
 
+    GET_CASE_APPOINTMENTLIST_SQL = """SELECT id, master_id, sdatum, edatum,
+    name, beschreibung, art FROM ka_fall_termine_tbl_view WHERE master_id =
+    %(id)s AND coalesce(edatum, sdatum)::date+1 >= %(date)s::date AND art = 0
+    ORDER BY sdatum """
+
+    GET_ALLCASES_APPOINTMENTLIST_SQL = """SELECT a.id, a.master_id, a.sdatum,
+    a.edatum, a.name, a.beschreibung, a.art FROM ka_fall_termine_tbl_view a
+    JOIN master_tbl_view m ON m.id = a.master_id JOIN ka_status_tbl_view s ON
+    m.id = s.master_id WHERE coalesce(edatum, sdatum)::date+1 >= %(date)s::date
+    AND art = 0 AND m.bearbeiter_id = %(editor)s AND s.status = 1 ORDER BY
+    sdatum """
+
     def __init__(self, caseid=None):
         afactory = CaseAppointmentFactory()
         today = datetime.now().replace(hour=0, minute=0, second=0,
                                        microsecond=0)
         if caseid:
             values = {'id': caseid, 'date': today}
-            sql = GET_CASE_APPOINTMENTLIST_SQL
+            sql = self.GET_CASE_APPOINTMENTLIST_SQL
         else:
             user = session['USER_AUTHORIZED']
             values = {'date': today, 'editor': user.id}
-            sql = GET_ALLCASES_APPOINTMENTLIST_SQL
+            sql = self.GET_ALLCASES_APPOINTMENTLIST_SQL
         self._load(afactory, sql, values)
 
 
 class GlobalAppointmentOverview(AppointmentOverview):
 
+    GET_GLOBAL_APPOINTMENTLIST_SQL = """SELECT id, master_id, sdatum, edatum,
+    name, beschreibung, art FROM ka_global_termine_tbl_view WHERE
+    coalesce(edatum, sdatum)::date+1 >= %(date)s::date ORDER BY sdatum """
+
     def __init__(self):
         afactory = GlobalAppointmentFactory()
         today = datetime.now().replace(hour=0, minute=0, second=0,
                                        microsecond=0)
         values = {'date': today}
-        sql = GET_GLOBAL_APPOINTMENTLIST_SQL
+        sql = self.GET_GLOBAL_APPOINTMENTLIST_SQL
         self._load(afactory, sql, values)
 
 
 class CaseReminderOverview(AppointmentOverview):
 
+    GET_CASE_REMINDERLIST_SQL = """SELECT id, master_id, sdatum, edatum,
+    name, beschreibung, art FROM ka_fall_termine_tbl_view WHERE master_id =
+    %(id)s AND art = 1 ORDER BY sdatum """
+
+    GET_ALLCASES_REMINDERLIST_SQL = """SELECT a.id, a.master_id, a.sdatum,
+    a.edatum, a.name, a.beschreibung, a.art FROM ka_fall_termine_tbl_view a
+    JOIN master_tbl_view m ON m.id = a.master_id JOIN ka_status_tbl_view s ON
+    m.id = s.master_id WHERE art = 1 AND m.bearbeiter_id = %(editor)s AND
+    s.status = 1 ORDER BY sdatum """
+
     def __init__(self, caseid=None):
         afactory = CaseReminderFactory()
         today = datetime.now().replace(hour=0, minute=0, second=0,
                                        microsecond=0)
         if caseid:
             values = {'id': caseid, 'date': today}
-            sql = GET_CASE_REMINDERLIST_SQL
+            sql = self.GET_CASE_REMINDERLIST_SQL
         else:
             user = session['USER_AUTHORIZED']
             values = {'date': today, 'editor': user.id}
-            sql = GET_ALLCASES_REMINDERLIST_SQL
+            sql = self.GET_ALLCASES_REMINDERLIST_SQL
         self._load(afactory, sql, values)
 
 
@@ -420,20 +343,32 @@
 
 class GlobalAppointment(Appointment):
 
+    DELETE_GLOBAL_APPOINTMENT_SQL = "SELECT delete_global_termin_ds(%(id)s)"
+    STORE_GLOBAL_APPOINTMENT_SQL = """UPDATE ka_global_termine_tbl_view SET
+    sdatum = %(start_date)s::timestamp, edatum = %(end_date)s::timestamp, name
+    = %(title)s, beschreibung = %(description)s, art = %(type)s WHERE id =
+    %(id)s """
+
     def __init__(self):
         Appointment.__init__(self)
         self.type = 0
-        self.store_sql = STORE_GLOBAL_APPOINTMENT_SQL
-        self.delete_sql = DELETE_GLOBAL_APPOINTMENT_SQL
+        self.store_sql = self.STORE_GLOBAL_APPOINTMENT_SQL
+        self.delete_sql = self.DELETE_GLOBAL_APPOINTMENT_SQL
 
 
 class CaseAppointment(Appointment):
 
+    DELETE_CASE_APPOINTMENT_SQL = "SELECT delete_fall_termin_ds(%(id)s)"
+    STORE_CASE_APPOINTMENT_SQL = """UPDATE ka_fall_termine_tbl_view SET sdatum
+    = %(start_date)s::timestamp, edatum = %(end_date)s::timestamp, name =
+    %(title)s, beschreibung = %(description)s, art = %(type)s WHERE id = %(id)s
+    """
+
     def __init__(self):
         Appointment.__init__(self)
         self.type = 0
-        self.store_sql = STORE_CASE_APPOINTMENT_SQL
-        self.delete_sql = DELETE_CASE_APPOINTMENT_SQL
+        self.store_sql = self.STORE_CASE_APPOINTMENT_SQL
+        self.delete_sql = self.DELETE_CASE_APPOINTMENT_SQL
 
 
 class CaseReminder(CaseAppointment):
@@ -446,6 +381,30 @@
 
 class MaxSaveTimeReminderOverview(AppointmentOverview):
 
+    GET_OLDFINISHED_CASES = """SELECT m.id, s.zugriff,
+    getLastCaseAppointment(m.id) as last_date FROM master_tbl_view m JOIN
+    ka_status_tbl_view s ON s.master_id = m.id WHERE s.status <> 5 AND
+    m.bearbeiter_id = %%(editor)s AND extract(day from now()-s.zugriff) >
+    %%(maxdays)s AND phase in (%s) AND (%s) """
+
+    GET_OLDFINISHED_CASES_4_ADMIN = """SELECT m.id, s.zugriff,
+    getLastCaseAppointment(m.id) as last_date FROM master_tbl_view m JOIN
+    ka_status_tbl_view s ON s.master_id = m.id WHERE s.status <> 5 AND
+    extract(day from now()-s.zugriff) > %%(maxdays)s AND phase in (%s) AND
+    (%s)"""
+
+    GET_OLDACTIVE_CASES = """SELECT m.id, s.zugriff,
+    getLastCaseAppointment(m.id) AS last_date FROM (SELECT * FROM
+    ka_status_tbl_view WHERE zugriff < now() - interval '1 day' * %%(maxdays)s
+    AND status <> 5) s JOIN master_tbl_view m ON m.id = s.master_id WHERE phase
+    in (%s) AND (%s) AND m.bearbeiter_id = %%(editor)s """
+
+    GET_OLDACTIVE_CASES_4_ADMIN = """SELECT m.id, s.zugriff,
+    getLastCaseAppointment(m.id) AS last_date FROM (SELECT * FROM
+    ka_status_tbl_view WHERE zugriff < now() - interval '1 day' * %%(maxdays)s
+    AND status <> 5) s JOIN master_tbl_view m ON m.id = s.master_id WHERE phase
+    in (%s) AND (%s) """
+
     def __init__(self):
         self.appointment_list = []
         agency = Agency()
@@ -502,11 +461,11 @@
             conn = db.getConnection()
             cur = conn.cursor()
             if user.isAdmin():
-                sql = (GET_OLDFINISHED_CASES_4_ADMIN
+                sql = (self.GET_OLDFINISHED_CASES_4_ADMIN
                        % (",".join(g.mpuls_config.get('phases', 'finished')), remindercondition))
                 cur.execute(sql, {'maxdays': days})
             else:
-                sql = (GET_OLDFINISHED_CASES
+                sql = (self.GET_OLDFINISHED_CASES
                        % (",".join(g.mpuls_config.get('phases', 'finished')), remindercondition))
                 cur.execute(sql, {'maxdays': days, 
                                   'editor': user.id})
@@ -526,12 +485,12 @@
             conn = db.getConnection()
             cur = conn.cursor()
             if user.isAdmin():
-                sql = (GET_OLDACTIVE_CASES_4_ADMIN
+                sql = (self.GET_OLDACTIVE_CASES_4_ADMIN
                        % (",".join(g.mpuls_config.get('phases', 'active')), remindercondition))
                 cur.execute(sql, {'maxdays': days, 
                                   'editor': user.id})
             else:
-                sql = (GET_OLDACTIVE_CASES
+                sql = (self.GET_OLDACTIVE_CASES
                        % (",".join(g.mpuls_config.get('phases', 'active')), remindercondition))
                 cur.execute(sql, {'maxdays': days, 
                                   'editor': user.id})



More information about the Mpuls-commits mailing list