[Mpuls-commits] r2525 - in wasko/branches/2.0/mpulsweb: controllers model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Apr 26 16:41:14 CEST 2010


Author: torsten
Date: 2010-04-26 16:41:13 +0200 (Mon, 26 Apr 2010)
New Revision: 2525

Modified:
   wasko/branches/2.0/mpulsweb/controllers/case_bundle.py
   wasko/branches/2.0/mpulsweb/model/case.py
Log:
Implemented first version of export


Modified: wasko/branches/2.0/mpulsweb/controllers/case_bundle.py
===================================================================
--- wasko/branches/2.0/mpulsweb/controllers/case_bundle.py	2010-04-26 13:48:55 UTC (rev 2524)
+++ wasko/branches/2.0/mpulsweb/controllers/case_bundle.py	2010-04-26 14:41:13 UTC (rev 2525)
@@ -8,10 +8,12 @@
 from pylons import app_globals as g
 from pylons.i18n import _, ungettext
 
+from formed.meta.data import PageNode
+
 from mpulsweb.lib.base import c, render, request, session, BaseController
 from mpulsweb.lib.security import checkRole
 from mpulsweb.lib.validators import BundleActionForm, SetBundleEditorForm, \
-    SetBundleStandinForm
+    SetBundleStandinForm, ExportSelectorValidator
 from mpulsweb.lib.helper.filters import NA
 from mpulsweb.model.user import UserGroupList, UserListObject, UserObject
 from mpulsweb.model.case import MpulsCaseBundle, MpulsCaseOverview
@@ -79,8 +81,7 @@
 auf "OK", um fortzufahren."""
 
 DIALOG_CONFIRM_EXPORT = u'''Fallakten exportieren?'''
-DIALOG_CONFIRM_EXPORT_EXPLAINATION = u'''\
-Wollen Sie wirklich die folgenden Fallakten exportieren?%s'''
+DIALOG_CONFIRM_EXPORT_EXPLAINATION = u'''%s'''
 EXPORT_SUCCESS_HEADER = u"""Fallakten exportiert!"""
 EXPORT_SUCCESS_TEXT = u"""\
 Es wurden %s Fallakten erfolgreich exportiert. Bitte klicken Sie
@@ -222,7 +223,7 @@
                     return self._empty_caselist()
                 session['casebundle'] = case_bundle
                 session.save()
-                return self.exportXML(0)
+                return self.export('XML')
 
             if action == 'exportCSV':
                 # Fiter out case which are not open(1) or inavtice (2)
@@ -467,56 +468,37 @@
             return render('/casebundle/standin.mako')
 
     # EXPORT
-    @checkRole(('admin', 'cm'))
-    def exportXML(self, confirmed):
-        confirmed = self._checkBool(confirmed)
+    def export(self, type="XML"):
         c.context = "../main.mako"
         case_bundle = session.get('casebundle')
-        if confirmed == 1:
-            num, export = case_bundle.export()
-            del session['casebundle']
-            return self._downloadXMLExport(export)
-        else:
-            c.dialog_title = DIALOG_CONFIRM_EXPORT
-            c.dialog_text = (DIALOG_CONFIRM_EXPORT_EXPLAINATION
+        data = {'exporttype': type, 
+                'exportanonym': '1',
+                'exportselection': [i.getName() for i in g.formedTree.findAllByClass(PageNode)]}
+        c.dialog_title = DIALOG_CONFIRM_EXPORT
+        c.dialog_text = (DIALOG_CONFIRM_EXPORT_EXPLAINATION
                              % "\n".join(self._buildCaseList(case_bundle)))
-            c.url_yes = "/case_bundle/exportXML/1"
-            c.url_no = "/case_overview/"
-            return render('/casemanagement/dialogs/confirm_export.mako')
+        form = render('/casemanagement/dialogs/confirm_export.mako')
+        return formencode.htmlfill.render(form, defaults=data,
+                                          auto_insert_errors=False,
+                                          errors={})
 
-    @checkRole(('admin', 'cm'))
-    def exportXLS(self, confirmed):
-        confirmed = self._checkBool(confirmed)
-        c.context = "../main.mako"
+    def exportAction(self):
+        validator = ExportSelectorValidator()
         case_bundle = session.get('casebundle')
-        if confirmed == 1:
-            num, export = case_bundle.export(type="XLS")
-            del session['casebundle']
+        form_result = validator.to_python(request.params)
+        exporttype = form_result.get('exporttype')
+        exportanonym = form_result.get('exportanonym') == '1'
+        exportselection = form_result.get('exportselection')
+        num, export = case_bundle.export(exporttype, 
+                                         exportanonym, 
+                                         exportselection)
+        del session['casebundle']
+        if exporttype == "XML":
+            return self._downloadXMLExport(export)
+        elif exporttype == "XLS":
             return self._downloadXLSExport(export)
-        else:
-            c.dialog_title = DIALOG_CONFIRM_EXPORT
-            c.dialog_text = (DIALOG_CONFIRM_EXPORT_EXPLAINATION
-                             % "\n".join(self._buildCaseList(case_bundle)))
-            c.url_yes = "/case_bundle/exportXLS/1"
-            c.url_no = "/case_overview/"
-            return render('/casemanagement/dialogs/confirm_export.mako')
-
-    @checkRole(('admin', 'cm'))
-    def exportCSV(self, confirmed):
-        confirmed = self._checkBool(confirmed)
-        c.context = "../main.mako"
-        case_bundle = session.get('casebundle')
-        if confirmed == 1:
-            num, export = case_bundle.export(type="CSV")
-            del session['casebundle']
+        elif exporttype == "CSV":
             return self._downloadCSVExport(export)
-        else:
-            c.dialog_title = DIALOG_CONFIRM_EXPORT
-            c.dialog_text = (DIALOG_CONFIRM_EXPORT_EXPLAINATION
-                             % "\n".join(self._buildCaseList(case_bundle)))
-            c.url_yes = "/case_bundle/exportCSV/1"
-            c.url_no = "/case_overview/"
-            return render('/casemanagement/dialogs/confirm_export.mako')
 
     def _downloadXMLExport(self, export):
         data = paste.fileapp.DataApp(

Modified: wasko/branches/2.0/mpulsweb/model/case.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/case.py	2010-04-26 13:48:55 UTC (rev 2524)
+++ wasko/branches/2.0/mpulsweb/model/case.py	2010-04-26 14:41:13 UTC (rev 2525)
@@ -397,11 +397,13 @@
                 log.exception(e)
         return num
 
-    def export(self, selection=None, type='XML'):
+    def export(self, type='XML', anonym=True, selection=None, ):
         factory = InstanceFactory(g.formedTree, PostgresDBInterface())
         num = 0
         try:
-            xmltree = factory.toXML(self.case_list)
+            xmltree = factory.toXML(self.case_list, 
+                                    selection=selection, 
+                                    anonymize=anonym)
             num = len(self.case_list) 
         except Exception, e:
             log.exception(e)



More information about the Mpuls-commits mailing list