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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 4 19:55:04 CET 2011


Author: bh
Date: 2011-11-04 19:55:03 +0100 (Fri, 04 Nov 2011)
New Revision: 5544

Modified:
   base/trunk/mpulsweb/model/case.py
   base/trunk/mpulsweb/model/document.py
Log:
Implement export of case documents.
This includes the function export_documents in the model that adds the
case documents to the export element tree instance and the code in
_export_additional_data in the case model that call export_documents if
the user has enabled the document export.


Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2011-11-04 17:36:20 UTC (rev 5543)
+++ base/trunk/mpulsweb/model/case.py	2011-11-04 18:55:03 UTC (rev 5544)
@@ -53,7 +53,7 @@
 from mpulsweb.lib.helpers import ensure_unicode, format_date, get_TagSetter
 from mpulsweb.lib.db import PostgresDBInterface, db
 
-from mpulsweb.model.document import listDocuments
+from mpulsweb.model.document import listDocuments, export_documents
 from mpulsweb.model.statement import PrivacyStatement
 from mpulsweb.model.phase import PhaseFactory, StartPhasePart, \
     PhaseAnonymizableCheckException, ConsistenceCheckException, PHASEFIELD, PC_MANUAL
@@ -439,12 +439,14 @@
 
     def _export_additional_data(self, case, case_id, cursor, selection,
                                 anonymize):
-        """Export logbook if selected and not anonymizing.
+        """Export logbook and documents if selected and not anonymizing.
         """
         if anonymize:
             return
         if "logbook" in selection:
             export_logbook(case, case_id, cursor, selection, anonymize)
+        if "documents" in selection:
+            export_documents(case, case_id, cursor, selection, anonymize)
 
     def formletter(self, letterid):
         factory = g.case_factory

Modified: base/trunk/mpulsweb/model/document.py
===================================================================
--- base/trunk/mpulsweb/model/document.py	2011-11-04 17:36:20 UTC (rev 5543)
+++ base/trunk/mpulsweb/model/document.py	2011-11-04 18:55:03 UTC (rev 5544)
@@ -26,16 +26,20 @@
 #
 # Authors:
 # Sascha L. Teichmann <teichmann at intevation.de>
+# Bernhard Herzog <bernhard.herzog at intevation.de>
 #
 
+import base64
 from mimetypes import guess_type
 import cStringIO as StringIO
+import xml.etree.ElementTree as ET
 
 import psycopg2  as dbapi
 
 import mpulsweb.lib.helpers as h
 from mpulsweb.lib.db import db
 from mpulsweb.lib.translation import _
+from mpulsweb.model.logbook import text_subelement
 
 
 MAX_SIZE = 10 * 1024 * 1024
@@ -243,4 +247,17 @@
         finally:
             db.recycleConnection(con, cur)
 
+
+def export_documents(case, case_id, cursor, selection, anonymize):
+    """Add the documents of the case with id case_id to the elementtree case"""
+    documents_element = ET.SubElement(case, "anlagen")
+    for document in listDocuments(case_id):
+        document.load(True)
+        document_element = ET.SubElement(documents_element, "anlage")
+        text_subelement(document_element, "anlage-mime", document.mime)
+        text_subelement(document_element, "anlage-name", document.name)
+        text_subelement(document_element, "anlage-daten",
+                        base64.b64encode(document.data))
+
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list