[Mpuls-commits] r4213 - in base/trunk: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Nov 16 21:47:58 CET 2010


Author: bh
Date: 2010-11-16 21:47:57 +0100 (Tue, 16 Nov 2010)
New Revision: 4213

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/export.py
Log:
* mpulsweb/lib/export.py (to_str, Sheet, Book): Removed.  No
longer needed.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-11-16 20:45:35 UTC (rev 4212)
+++ base/trunk/ChangeLog	2010-11-16 20:47:57 UTC (rev 4213)
@@ -1,5 +1,10 @@
 2010-11-16  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/export.py (to_str, Sheet, Book): Removed.  No
+	longer needed.
+
+2010-11-16  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/export.py (XLSTable, XLSContainer): New. XLS export
 	classes derived from the new base classes Table and Container.
 	They effectively replace the old XLS export code.

Modified: base/trunk/mpulsweb/lib/export.py
===================================================================
--- base/trunk/mpulsweb/lib/export.py	2010-11-16 20:45:35 UTC (rev 4212)
+++ base/trunk/mpulsweb/lib/export.py	2010-11-16 20:47:57 UTC (rev 4213)
@@ -165,110 +165,8 @@
 
 
 
-def to_str(x):
-    t = type(x)
-    if t in (IntType, LongType):
-        return x
-    if t in StringTypes:
-        if not isinstance(x, unicode):
-            x = unicode(x, "utf-8")
-        if len(x) > 32765:
-            x = x[:32765]
-        return x
-    return str(x)
 
 
-class Sheet(object):
-
-    def __init__(self, worksheet, column_names, rg=False, rgname=None):
-        for idx, name in enumerate(column_names):
-            worksheet.write(0, idx, name)
-
-        self.worksheet = worksheet
-        self.names = column_names
-        self.rg = rg
-        self.rgname = rgname
-        self.row = 1
-        self.column = 0
-
-    def next_row(self):
-        self.row += 1
-        self.column = 0
-
-    def add_data(self, value):
-        if not value is None:
-            self.worksheet.write(self.row, self.column, to_str(value))
-        self.column += 1
-
-
-class Book:
-
-    def __init__(self, tree, selection):
-        self.tree = tree
-        self.selection = selection
-        self.workbook = pyExcelerator.Workbook()
-        self.collectors = {}
-        self.sheets = {}
-        self.pages = g.formedTree.findAllByClass(PageNode)
-
-        for p in self.pages:
-            rg = False
-            rgname = None
-            # Is this a rg?
-            if isinstance(p.getParent(), RepeatNode):
-                rg = True
-                rgname = p.getParent().getName()
-                names = ["id", "master_id"]
-            else:
-                names = ["id"]
-            collector = WidgetCollector()
-            p.visit(collector.visitor)
-
-            if p.getName() not in self.selection:
-                continue
-
-            sheet = self.workbook.add_sheet(p.getDescription())
-            names.extend([w.getName() for w in collector.widgets])
-
-            #save
-            self.sheets[p.getName()] = Sheet(sheet, names, rg, rgname)
-            self.collectors[p.getName()] = collector
-
-    def fill(self):
-        for name, sheet in self.sheets.iteritems():
-            rg_ids = itertools.count()
-            for case_id, case in enumerate(self.tree.getiterator('master')):
-                # Handling of rg. Does not work for nested rg.
-                if sheet.rg:
-                    for rg in case.findall(sheet.rgname):
-                        for col, field in enumerate(sheet.names):
-                            try:
-                                value = rg.find(field).text
-                            except:
-                                if field == "id":
-                                    value = rg_ids.next()
-                                elif field == "master_id":
-                                    value = case_id
-                                else:
-                                    value = ""
-                            sheet.add_data(value)
-                        sheet.next_row()
-                else:
-                    for col, field in enumerate(sheet.names):
-                        try:
-                            value = case.find(field).text
-                        except:
-                            if field == "id":
-                                value = case_id
-                            else:
-                                value = ""
-                        sheet.add_data(value)
-                    sheet.next_row()
-
-    def write_xls(self, fname):
-        self.workbook.save(fname)
-
-
 class XLSTable(Table):
 
     def add_to_workbook(self, workbook):



More information about the Mpuls-commits mailing list