[Mpuls-commits] r438 - in wasko/trunk: . waskaweb/controllers waskaweb/lib waskaweb/templates/casemanagement

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 27 11:44:01 CET 2009


Author: teichmann
Date: 2009-03-27 11:44:00 +0100 (Fri, 27 Mar 2009)
New Revision: 438

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/controllers/case_overview.py
   wasko/trunk/waskaweb/lib/csv.py
   wasko/trunk/waskaweb/templates/casemanagement/downloadCSV.mako
   wasko/trunk/waskaweb/templates/casemanagement/overview.mako
Log:
Reactivated CSV export.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-27 09:42:05 UTC (rev 437)
+++ wasko/trunk/ChangeLog.txt	2009-03-27 10:44:00 UTC (rev 438)
@@ -1,5 +1,16 @@
 2009-03-27	Sascha L. Teichmann <sascha.teichmann at intevation.de>
 
+	* waskaweb/controllers/case_overview.py:set rendering for logbook
+	  and documents to false in parts selection of CSV export.
+
+	* waskaweb/lib/csv.py: Only export master table.
+
+	* waskaweb/templates/casemanagement/overview.mako: Reactive CSV export
+
+	* waskaweb/templates/casemanagement/downloadCSV.mako: s/WASKA/WASKO/
+
+2009-03-27	Sascha L. Teichmann <sascha.teichmann at intevation.de>
+
 	* waskaweb/controllers/caselifetime.py: outcomment debugging prints.
 
 2009-03-27	Torsten Irlaender  <torsten.irlaender at intevation.de> 

Modified: wasko/trunk/waskaweb/controllers/case_overview.py
===================================================================
--- wasko/trunk/waskaweb/controllers/case_overview.py	2009-03-27 09:42:05 UTC (rev 437)
+++ wasko/trunk/waskaweb/controllers/case_overview.py	2009-03-27 10:44:00 UTC (rev 438)
@@ -726,6 +726,8 @@
         c.store_action       = h.url_for(action="storeSelectedCSVParts")
         c.back_url           = h.url_for(controller='/case_overview', action='exportCSV', confirmed=1)
         c.back_title         = "CSV Export"
+        c.selectLogbook      = False
+        c.selectDocuments    = False
         page = render('casemanagement/selectParts.mako')
         return formencode.htmlfill.render(unicode(page, 'utf-8'),defaults=selection_checker.selections)
 

Modified: wasko/trunk/waskaweb/lib/csv.py
===================================================================
--- wasko/trunk/waskaweb/lib/csv.py	2009-03-27 09:42:05 UTC (rev 437)
+++ wasko/trunk/waskaweb/lib/csv.py	2009-03-27 10:44:00 UTC (rev 438)
@@ -30,11 +30,11 @@
 
 from types import StringTypes
 
-from sql_helper import range_compress, where_ids
+from datetime import datetime
 
-import sys
+from exportselection import SelectorFactory, CasePartsSelection
 
-from exportselection import SelectorFactory, CasePartsSelection, RG_ALL
+from helpers import dd_mm_YYYY
 
 SEP = "\t"
 
@@ -48,155 +48,10 @@
         x = unicode(str(x), "utf-8")
         return x.replace("\r", "").replace("\n", " ").replace(SEP, "    ")
     if x is None: return ""
-    return x
+    if isinstance(x, datetime): return dd_mm_YYYY(x)
+    return str(x)
 
-class RepeatGroup:
-
-    def __init__(self):
-        self.headers = None
-        self.values  = None
-
-    def headerFields(self):
-        return self.headers
-
-    def valueFields(self):
-        return self.values
-
-    def numFields(self):
-        return len(self.values)
-
-    def setColumns(self, headers, values):
-        self.headers = headers
-        self.values  = values
-
-class Case(RepeatGroup):
-
-    def __init__(self, orig_pos):
-        RepeatGroup.__init__(self)
-        self.orig_pos = orig_pos
-        self.rgs = [[] for i in range(len(RG_ALL))]
-        
-    def appendRepeatGroup(self, rg, index):
-        self.rgs[index].append(rg)
-
-class Cases:
-    def __init__(self, anonymize=False):
-        self.cases     = None
-        self.anonymize = anonymize
-
-    def fetchCases(self, cur, ids, selector_factory):
-
-        case_hash = dict([(x[1], Case(x[0])) for x in enumerate(ids)])
-        ids.sort()
-        ids = range_compress(ids)
-
-        master_where = where_ids(ids)
-        rg_where     = where_ids(ids, 'master_id')
-
-        selector = selector_factory.createSelector(master_where, rg_where)
-
-        stmnt = selector.getSelectStatementByView('master_tbl')
-
-        #print >> sys.stderr, "stmnt: %s" % stmnt
-
-        cur.execute(stmnt)
-
-        headers, used_indices = None, None
-
-        while True:
-            row = cur.fetchone()
-            if not row: break
-
-            if used_indices is None:
-                used_indices = [t[0] for t in enumerate(cur.description) if t[1][0] not in BLACK_LIST]
-                headers      = [cur.description[i][0] for i in used_indices]
-
-            values = [row[i] for i in used_indices]
-
-            case_hash[row[0]].setColumns(headers, values)
-
-        for index, view in enumerate(RG_ALL):
-
-            headers, used_indices = None, None
-
-            stmnt = selector.getSelectStatementByView(view)
-
-            if not stmnt: continue
-
-            cur.execute(stmnt)
-
-            while True:
-                row = cur.fetchone()
-                if not row: break
-                if used_indices is None:
-                    used_indices = [t[0] for t in enumerate(cur.description) if t[1][0] not in BLACK_LIST]
-                    headers      = [cur.description[i][0] for i in used_indices]
-
-                values = [row[i] for i in used_indices]
-
-                rg = RepeatGroup()
-                rg.setColumns(headers, values)
-                case_hash[row[1]].appendRepeatGroup(rg, index)
-
-        self.cases = case_hash.values()
-        self.cases.sort(lambda a, b: cmp(a.orig_pos, b.orig_pos))
-
-    def maxRepeatGroups(self):
-        mc = [0] * len(RG_ALL)
-        for rgs in [c.rgs for c in self.cases]:
-            for i in range(len(mc)):
-                mc[i] = max(mc[i], len(rgs[i]))
-        self.maxRGs = mc
-
-    def noneEmptyRepeatGroup(self, i):
-        for case in self.cases:
-            rgs = case.rgs
-            if len(rgs[i]):
-                return rgs[i][0]
-        return None
-
-    def generateHeader(self, out):
-        if not self.cases:
-            return ""
-        case = self.cases[0]
-        headers = case.headerFields()
-        for i in range(len(RG_ALL)):
-            rg = self.noneEmptyRepeatGroup(i)
-            if rg is None:
-                continue
-            hs = rg.headerFields() 
-            for j in range(self.maxRGs[i]):
-                if j > 0:
-                    headers.extend([ "%s$%d" % (x, j) for x in hs])
-                else:
-                    headers.extend(hs)
-        print >> out, "#%s" % SEP.join(headers)
-
-    def dumpFields(self, out):
-        fills = []
-        for i in range(len(RG_ALL)):
-            rg = self.noneEmptyRepeatGroup(i)
-            if rg is None: c = 0
-            else:          c = rg.numFields()
-            fills.append([''] * c)
-            
-        for case in self.cases:
-            line = case.valueFields()
-            for m, rg, fill in zip(self.maxRGs, case.rgs, fills):
-                count = 0
-                for r in rg:
-                    line.extend(r.valueFields())
-                    count += 1
-                while count < m:
-                    line.extend(fill)
-                    count += 1
-            print >> out, "%s" % SEP.join(map(lambda x: u"%s" % strReplace(x), line))
-
-
 def exportAsCSV(cur, out, ids=None, case_parts=None, anonymize=False):
-    #from datetime import datetime
-    #start = datetime.now()
-    cases = Cases(anonymize)
     if ids is None:
         cur.execute(FETCH_ALL_IDS)
         ids = []
@@ -209,14 +64,27 @@
         case_parts = CasePartsSelection()
 
     selector_factory = SelectorFactory(case_parts, anonymize)
+    selector = selector_factory.createSelector()
 
-    cases.fetchCases(cur, ids, selector_factory)
+    stmnt = selector.getSelectStatementByView("master_tbl")
+    if not stmnt: return
 
-    cases.maxRepeatGroups()
-    cases.generateHeader(out)
-    cases.dumpFields(out)
+    used_indices = None
 
-    #stop = datetime.now()
-    #print >> sys.stderr, "export took: %s" % (stop-start)
+    mid = {}
+    for id in ids:
+        mid['id'] = id
+        cur.execute(stmnt, mid)
+        row = cur.fetchone()
+        if not row: continue
+        if used_indices is None:
+            headers, used_indices = [], []
+            for idx, d in enumerate(cur.description):
+                if d[0] not in BLACK_LIST:
+                    used_indices.append(idx)
+                    headers.append(strReplace(d[0]))
+            print >> out, SEP.join(headers)
 
-# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
+        print >> out, SEP.join([strReplace(row[idx]) for idx in used_indices])
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

Modified: wasko/trunk/waskaweb/templates/casemanagement/downloadCSV.mako
===================================================================
--- wasko/trunk/waskaweb/templates/casemanagement/downloadCSV.mako	2009-03-27 09:42:05 UTC (rev 437)
+++ wasko/trunk/waskaweb/templates/casemanagement/downloadCSV.mako	2009-03-27 10:44:00 UTC (rev 438)
@@ -14,7 +14,7 @@
 <div class="export_box_dialog error_font">
 <strong>Achtung:</strong> Diese CSV-Datei ist für das Öffnen in verschiedenen
 Office-Produkten z.B. Microsoft-Excel nicht geeignet. Weitere Details
-hierzu lesen Sie bitte im WASKA-Anwendungshandbuch nach.
+hierzu lesen Sie bitte im WASKO-Anwendungshandbuch nach.
 </div>
 
 %if not c.isEvaluationServer:

Modified: wasko/trunk/waskaweb/templates/casemanagement/overview.mako
===================================================================
--- wasko/trunk/waskaweb/templates/casemanagement/overview.mako	2009-03-27 09:42:05 UTC (rev 437)
+++ wasko/trunk/waskaweb/templates/casemanagement/overview.mako	2009-03-27 10:44:00 UTC (rev 438)
@@ -39,7 +39,7 @@
         <option value="stand-in">Vertretung zuweisen</option>
       <option value="exportXLS">Als Excel-Tabellen exportieren</option>
       <option value="exportXML">Als XML-Datei exportieren</option>
-      ##<option value="exportCSV">Als CSV-Datei exportieren</option>
+      <option value="exportCSV">Als CSV-Datei exportieren</option>
       ##% if not c.hide_evaluation:
       ##  <option value="evaluate">Auswerten</option>
       ##% endif



More information about the Mpuls-commits mailing list