[Mpuls-commits] r4864 - in base/trunk: . mpulsweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Apr 5 16:49:29 CEST 2011
Author: torsten
Date: 2011-04-05 16:49:27 +0200 (Tue, 05 Apr 2011)
New Revision: 4864
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/model/case.py
Log:
Improved formletterfunction. No need for parsing sql anymore.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2011-04-05 14:02:28 UTC (rev 4863)
+++ base/trunk/ChangeLog 2011-04-05 14:49:27 UTC (rev 4864)
@@ -6,6 +6,8 @@
mpulsweb/lib/export.py: Implemented serial letters according to MEP-1.
Export now always includes all defined fields in the defined order
(specified by sql query).
+ * mpulsweb/model/case.py (MpulsCase.formletter): Improved
+ formletterfunction. No need for parsing sql anymore.
2011-03-31 Ludwig Reiter <ludwig.reiter at intevation.de>
Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py 2011-04-05 14:02:28 UTC (rev 4863)
+++ base/trunk/mpulsweb/model/case.py 2011-04-05 14:49:27 UTC (rev 4864)
@@ -1027,18 +1027,6 @@
letter = None
conn, cur = None, None
- def get_fields(sql):
- fields = []
- sql = sql.lower()
- r = re.compile('select (.*) from')
- m = r.match(sql)
- if m:
- fields_str = m.group(1)
- fields_raw = fields_str.split(',')
- for f in fields_raw:
- fields.append(f.split('as')[-1].strip())
- return fields
-
# Search for formletter
for letter in g.mpuls_config.get('case', 'formletter'):
if letter.get('id') == str(id): break
@@ -1046,15 +1034,16 @@
try:
try:
conn = db.getConnection()
- cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
+ cur = conn.cursor()
d = {'id': self.id}
for sql in letter.get('sql'):
- order.extend(get_fields(sql))
cur.execute(sql, d)
+ desc = [t[0] for t in cur.description]
+ order.extend(desc)
result = cur.fetchone()
if result:
- for k, v in result.iteritems():
- fields[k] = v
+ for n, k in enumerate(desc):
+ fields[k] = result[n]
finally:
db.recycleConnection(conn, cur)
except:
More information about the Mpuls-commits
mailing list