[Mpuls-commits] r2520 - wasko/branches/2.0/mpulsweb/model

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


Author: torsten
Date: 2010-04-26 14:08:31 +0200 (Mon, 26 Apr 2010)
New Revision: 2520

Modified:
   wasko/branches/2.0/mpulsweb/model/case.py
Log:
Added export for casebunles


Modified: wasko/branches/2.0/mpulsweb/model/case.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/case.py	2010-04-26 12:06:43 UTC (rev 2519)
+++ wasko/branches/2.0/mpulsweb/model/case.py	2010-04-26 12:08:31 UTC (rev 2520)
@@ -30,6 +30,7 @@
 import logging
 from datetime import datetime
 from sets import Set
+from xml.etree import ElementTree
 
 import psycopg2.extras
 
@@ -40,6 +41,7 @@
 from formed.instance.tree import SetDataException
 
 from mpulsweb.lib.base import g, h, session
+from mpulsweb.lib.export import XLSExport, CSVExport 
 from mpulsweb.lib.anonymize import determineAnonymizedCaseEndPhase
 from mpulsweb.lib.helpers import ensure_unicode
 from mpulsweb.lib.db import PostgresDBInterface, db
@@ -395,7 +397,36 @@
                 log.exception(e)
         return num
 
+    def export(self, selection=None, type='XML'):
+        factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+        num = 0
+        try:
+            xmltree = factory.toXML(self.case_list)
+            num = len(self.case_list) 
+        except Exception, e:
+            log.exception(e)
 
+        if type == "XML":
+            export = self._exportXML(xmltree) 
+        elif type== "XLS":
+            export = self._exportXSL(xmltree) 
+        elif type== "CSV":
+            export = self._exportCSV(xmltree) 
+
+        return num, export
+
+    def _exportXML(self, tree):
+        root = tree.getroot()
+        xml = ElementTree.tostring(root)
+        return xml
+
+    def _exportXSL(self, tree):
+        return XLSExport().export(tree)
+    
+    def _exportCSV(self, tree):
+        return CSVExport().export(tree)
+
+
 class MpulsCaseStandin:
 
     """This class represents the standin for a case"""
@@ -829,7 +860,6 @@
             ps.keepUndefined()
         self.getState().setState(1)
 
-
 class SessionCase:
 
     """This class holds all needed information for the currently selected case



More information about the Mpuls-commits mailing list