[Mpuls-commits] r2019 - wasko/branches/2.0/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 19 08:25:10 CET 2010


Author: torsten
Date: 2010-03-19 08:25:09 +0100 (Fri, 19 Mar 2010)
New Revision: 2019

Modified:
   wasko/branches/2.0/mpulsweb/model/case.py
Log:
Added missing SQL statements


Modified: wasko/branches/2.0/mpulsweb/model/case.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/case.py	2010-03-19 07:14:14 UTC (rev 2018)
+++ wasko/branches/2.0/mpulsweb/model/case.py	2010-03-19 07:25:09 UTC (rev 2019)
@@ -49,6 +49,18 @@
 
 LOAD_CASE_SQL = """SELECT %(fields)s FROM master_tbl_view WHERE id = %%(id)s"""
 
+#SQL
+LOAD_STANDIN_SQL = """
+SELECT n.benutzer_id
+FROM nm_benutzer_master_tbl_view n
+JOIN master_tbl_view m ON m.id = n.master_id
+WHERE m.id = %(id)s"""
+ADD_STANDIN_SQL = """
+SELECT create_nm_benutzer_master_ds(%(groupid)s, %(caseid)s)"""
+DELETE_STANDIN_SQL = """
+SELECT delete_nm_benutzer_master_ds(%(groupid)s, %(caseid)s)"""
+
+#DIALOGS
 MARKANONYMIZE_FAILED_MIN_PHASE = u"""\
 <p>Eine Anonymisierung ist für Fälle in der Phase "%s" nicht
 vorgesehen.</p>
@@ -59,6 +71,7 @@
 <p>Eine Anonymisierung ist für diese Fallakte derzeit nicht möglich: Es können nur Fälle beendet werden, deren aktuelle Phase beendet wurde. Die Phase "%s" is derzeit noch nicht beendet. Bitte beenden Sie die Phase und versuchen Sie erneut eine Anonymisierung.</p> Klicken Sie auf "OK", um fortzufahren.</p>
 """
 
+
 class LoadCaseNotExistsError(Exception):
 
     def __init__(self, value):
@@ -316,9 +329,77 @@
         return num
 
 
+class MpulsCaseStandin:
+    """This class represents the standin for a case"""
+    def __init__(self, case_id=None):
+        self.case_id = case_id
+        self.group_ids = []
+        self._loadFromDB()
 
+    def _loadFromDB(self):
+        fields = {'id': self.case_id}
+        con, cur = None, None
+        try:
+            con = db.getConnection()
+            cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
+            cur.execute(LOAD_STANDIN_SQL, fields)
+            rows = cur.fetchall()
+            for row in rows:
+                self.group_ids.append(row['benutzer_id'])
+        finally:
+            db.recycleConnection(con, cur)
 
+    def getGroups(self):
+        """Returns a list of group ids"""
+        return self.group_ids
 
+    def setGroups(self, groupid_list):
+        """Sets the Standin to the provided list of group ids"""
+        old = Set(self.getGroups())
+        new = Set(groupid_list)
+        self._delete(old - new)
+        self._add(new - old)
+
+    def _delete(self, groupid_list):
+        con, cur = None, None
+        fields = {'caseid': self.case_id, 'groupid': None}
+        try:
+            con = db.getConnection()
+            for uid in groupid_list:
+                fields['groupid'] = uid
+                cur = con.cursor()
+                try:
+                    cur.execute(DELETE_STANDIN_SQL, fields)
+                except:
+                    con.rollback()
+                cur.close()
+                cur = None
+            con.commit()
+        finally:
+            db.recycleConnection(con, cur)
+
+    def _add(self, groupid_list):
+        con, cur = None, None
+        fields = {'caseid': self.case_id, 'groupid': None}
+        try:
+            con = db.getConnection()
+            for uid in groupid_list:
+                fields['groupid'] = uid
+                cur = con.cursor()
+                try:
+                    cur.execute(ADD_STANDIN_SQL, fields)
+                except:
+                    con.rollback()
+                cur.close()
+                cur = None
+            con.commit()
+        finally:
+            db.recycleConnection(con, cur)
+
+
+
+
+
 class MpulsCase:
 
     def __init__(self, id=None, preset=None):



More information about the Mpuls-commits mailing list