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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 11 15:39:24 CET 2011


Author: torsten
Date: 2011-02-11 15:39:23 +0100 (Fri, 11 Feb 2011)
New Revision: 4612

Modified:
   base/trunk/mpulsweb/model/case.py
Log:
* mpulsweb/model/case.py (MpulsCase.formletter): Added new function to
model to fetch fields required for a formletter and returns a
dictionary which includes all fetched fields as key, value pairs


Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2011-02-11 14:34:55 UTC (rev 4611)
+++ base/trunk/mpulsweb/model/case.py	2011-02-11 14:39:23 UTC (rev 4612)
@@ -1005,7 +1005,31 @@
             ps.keepUndefined()
         self.getState().setState(1)
 
+    def formletter(self, id):
+        """Returns a dictionary with fields required for a formletter""" 
+        fields = {}
+        letter = None
+        conn, cur = None, None
 
+        # Search for formletter
+        for letter in g.mpuls_config.get('case', 'formletter'):
+            if letter.get('id') == str(id): break
+
+        try:
+            try:
+                conn = db.getConnection()
+                cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
+                d = {'id': self.id}
+                for sql in letter.get('sql'):
+                    cur.execute(sql, d)
+                    for k, v in cur.fetchone().iteritems():
+                        fields[k] = v
+            finally:
+                db.recycleConnection(conn, cur)
+        except:
+            log.exception(_('Error on fetching data for formletter'))
+        return fields 
+
 class SessionCase:
 
     """This class holds all needed information for the currently selected case



More information about the Mpuls-commits mailing list