[Mpuls-commits] r4614 - base/trunk/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 11 17:55:17 CET 2011


Author: torsten
Date: 2011-02-11 17:55:16 +0100 (Fri, 11 Feb 2011)
New Revision: 4614

Modified:
   base/trunk/mpulsweb/controllers/case.py
Log:
* mpulsweb/controllers/case.py (CaseController.formletter): 
	Added new function to export different versions of formletters. Will
	return a XLS file with defined fields from the database.


Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py	2011-02-11 16:52:36 UTC (rev 4613)
+++ base/trunk/mpulsweb/controllers/case.py	2011-02-11 16:55:16 UTC (rev 4614)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 from datetime import datetime
 import logging
+import paste
 import formencode
 
 from pylons import request, tmpl_context as c, app_globals as g
@@ -13,6 +14,7 @@
 from mpulsweb.lib.security import checkRole
 from mpulsweb.lib.dialogs import checkPrivacyStatement
 from mpulsweb.lib.validators import SetStandinForm, SetEditorForm, NewCaseForm
+from mpulsweb.lib.export import FormletterExport 
 from mpulsweb.lib.anonymize import determineAnonymizedCaseEndPhaseName, \
      determineAnonymizedCaseEndPhase
 from mpulsweb.lib.db import  PostgresDBInterface
@@ -544,4 +546,24 @@
 
         pass
 
+    ## Export
+
+    def _download_data(self, data, mime_type, extension, **extra):
+        disposition = 'attachment; filename="formletter.%s"' % extension
+        data = paste.fileapp.DataApp(data,
+                                     content_type=mime_type,
+                                     content_disposition=disposition,
+                                     cache_control='must-revalidate',
+                                     pragma='public',
+                                     **extra)
+        return data(request.environ, self.start_response)
+
+    def formletter(self, id, letterid=1):
+        id = self._checkInt(id)
+        case = self._loadCase(id)
+        d = case.formletter(letterid)
+        export = FormletterExport([d]).export() 
+        return self._download_data(export, "application/msexcel", "xls")
+
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list