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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 4 20:13:39 CET 2011


Author: bh
Date: 2011-11-04 20:13:37 +0100 (Fri, 04 Nov 2011)
New Revision: 5546

Modified:
   base/trunk/mpulsweb/model/document.py
Log:
Extract listing of documents from listDocuments into the new function
list_documents_with_cursor. The new function is more low-level and
requires that a database cursor has already been created. The
listDocuments function now mostly just creates a database cursor and
calls list_documents_with_cursor to do the actual work.

The list_documents_with_cursor function will be necessary for importing
documents attached to cases from XML files.


Modified: base/trunk/mpulsweb/model/document.py
===================================================================
--- base/trunk/mpulsweb/model/document.py	2011-11-04 19:01:42 UTC (rev 5545)
+++ base/trunk/mpulsweb/model/document.py	2011-11-04 19:13:37 UTC (rev 5546)
@@ -101,27 +101,33 @@
         return repr(self.value)
 
 
+def list_documents_with_cursor(cursor, case_id):
+    documents = []
+
+    if case_id is None:
+        cursor.execute(LIST_GLOBAL)
+    else:
+        cursor.execute(LIST_CASE, {'master_id': case_id})
+
+    while True:
+        row = cursor.fetchone()
+        if not row:
+            break
+        id, case, size, mime, name = row
+        documents.append(Document(id, case, size, mime, name))
+
+    return documents
+
+
 def listDocuments(case=None):
     if not case is None:
         case = int(case)
 
-    documents = []
-
     con, cur = None, None
     try:
         con = db.getConnection()
         cur = con.cursor()
-        if case is None:
-            cur.execute(LIST_GLOBAL)
-        else:
-            cur.execute(LIST_CASE, {'master_id': case})
-
-        while True:
-            row = cur.fetchone()
-            if not row:
-                break
-            id, case, size, mime, name = row
-            documents.append(Document(id, case, size, mime, name))
+        return list_documents_with_cursor(cur, case)
     finally:
         db.recycleConnection(con, cur)
 



More information about the Mpuls-commits mailing list