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

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


Author: bh
Date: 2010-11-16 21:01:14 +0100 (Tue, 16 Nov 2010)
New Revision: 4208

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/export.py
Log:
* mpulsweb/lib/export.py (Table.__init__): New parameter and
instance variable title.  Not needed by CSV export but will be
needed to export to XLS
(Container.create_tables): Gather table titles for repeat groups
and the master table and use them when creating the table objects.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-11-16 19:55:22 UTC (rev 4207)
+++ base/trunk/ChangeLog	2010-11-16 20:01:14 UTC (rev 4208)
@@ -1,5 +1,13 @@
 2010-11-16  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/export.py (Table.__init__): New parameter and
+	instance variable title.  Not needed by CSV export but will be
+	needed to export to XLS
+	(Container.create_tables): Gather table titles for repeat groups
+	and the master table and use them when creating the table objects.
+
+2010-11-16  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/export.py (Container, CSVContainer): Move
 	non-csv-specific code from CSVContainer into the new base class
 	Container and derive CSVContainer from that.  The Container

Modified: base/trunk/mpulsweb/lib/export.py
===================================================================
--- base/trunk/mpulsweb/lib/export.py	2010-11-16 19:55:22 UTC (rev 4207)
+++ base/trunk/mpulsweb/lib/export.py	2010-11-16 20:01:14 UTC (rev 4208)
@@ -59,9 +59,13 @@
 
     """A single Table for tabular output formats like XLS or CSV"""
 
-    def __init__(self, columns):
+    def __init__(self, title, columns):
         """Initialize the table.
-        The parameter columns is a list defining the column names"""
+        The parameter title is a string with the title of the table and
+        will usually be taken from the page or repeat group that is
+        represented by the table.  The parameter columns is a list
+        defining the column names"""
+        self.title = title
         self.columns = columns
         self.rows = []
 
@@ -88,6 +92,7 @@
     def create_tables(self, selection):
         table_columns = dict()
         repeat_groups = set()
+        titles = dict()
         for page in self.meta_tree.findAllByClass(PageNode):
             if page.getName() not in selection:
                 continue
@@ -96,18 +101,22 @@
             page.visit(collector.visitor)
             for nc in collector.widgets:
                 table_name = "master"
+                table_title = "Master"
                 for p in nc.pathToRoot():
                     if isinstance(p, RepeatNode):
                         table_name = p.getName()
+                        table_title = p.getDescription()
                         repeat_groups.add(table_name)
                         break
                 table_columns.setdefault(table_name, []).append(nc.getName())
+                titles[table_name] = table_title
 
         for name, columns in table_columns.iteritems():
             extra_columns = ["id"]
             if name in repeat_groups:
                 extra_columns.append("master_id")
-            self.tables[name] = self.table_factory(extra_columns + columns)
+            self.tables[name] = self.table_factory(titles[name],
+                                                   extra_columns + columns)
 
     def fill(self, tree):
         """Fill the tables with the contents of the ElementTree tree."""



More information about the Mpuls-commits mailing list