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

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


Author: bh
Date: 2011-11-04 20:42:59 +0100 (Fri, 04 Nov 2011)
New Revision: 5550

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

The delete_document_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:40:08 UTC (rev 5549)
+++ base/trunk/mpulsweb/model/document.py	2011-11-04 19:42:59 UTC (rev 5550)
@@ -147,6 +147,14 @@
     return document_id
 
 
+def delete_document_with_cursor(cursor, id, is_case_document):
+    if is_case_document:
+        statement = DELETE_CASE
+    else:
+        statement = DELETE_GLOBAL
+    cursor.execute(statement, {'id': id})
+
+
 def listDocuments(case=None):
     if not case is None:
         case = int(case)
@@ -161,12 +169,8 @@
 
 
 def deleteDocument(id, case=False):
-    id = int(id)
-    if case:
-        statement = DELETE_CASE
-    else:
-        statement = DELETE_GLOBAL
-    db.execute(statement, {'id': id})
+    with db.transaction() as cur:
+        delete_document_with_cursor(cur, int(id), case)
 
 
 class Document:



More information about the Mpuls-commits mailing list