[Mpuls-commits] r2619 - in wasko/branches/2.0: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue May 4 15:44:39 CEST 2010


Author: bh
Date: 2010-05-04 15:44:38 +0200 (Tue, 04 May 2010)
New Revision: 2619

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/mpulsweb/lib/export.py
Log:
* mpulsweb/lib/export.py (Book.__init__): Add columns for ids and
master_ids (the latter only for repeat groups)
(Book.fill): Generate ficticious but consistent ids for cases and
repeat groups.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-05-04 12:47:44 UTC (rev 2618)
+++ wasko/branches/2.0/ChangeLog	2010-05-04 13:44:38 UTC (rev 2619)
@@ -1,3 +1,13 @@
+2010-05-04  Bernhard Herzog  <bh at intevation.de>
+
+	Add ids to the generated XLS files so that relation ship between
+	the data on the various pages can be established by the user.
+
+	* mpulsweb/lib/export.py (Book.__init__): Add columns for ids and
+	master_ids (the latter only for repeat groups)
+	(Book.fill): Generate ficticious but consistent ids for cases and
+	repeat groups.
+
 2010-05-04  Roland Geider <roland.geider at intevation.de>
 
 	* mpulsweb/public/styles/ie8.css:

Modified: wasko/branches/2.0/mpulsweb/lib/export.py
===================================================================
--- wasko/branches/2.0/mpulsweb/lib/export.py	2010-05-04 12:47:44 UTC (rev 2618)
+++ wasko/branches/2.0/mpulsweb/lib/export.py	2010-05-04 13:44:38 UTC (rev 2619)
@@ -1,6 +1,7 @@
 from types import StringTypes, IntType, LongType
 from StringIO import StringIO
 import logging
+import itertools
 
 import pyExcelerator
 
@@ -83,6 +84,9 @@
             if isinstance(p.getParent(), RepeatNode):
                 rg = True
                 rgname = p.getParent().getName()
+                names = ["id", "master_id"]
+            else:
+                names = ["id"]
             collector = WidgetCollector()
             p.visit(collector.visitor)
 
@@ -90,7 +94,7 @@
                 continue
 
             sheet = self.workbook.add_sheet(p.getDescription())
-            names = [w.getName() for w in collector.widgets]
+            names.extend([w.getName() for w in collector.widgets])
 
             #save
             self.sheets[p.getName()] = Sheet(sheet, names, rg, rgname)
@@ -98,7 +102,8 @@
 
     def fill(self):
         for name, sheet in self.sheets.iteritems():
-            for case in self.tree.getiterator('master'):
+            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):
@@ -106,7 +111,12 @@
                             try:
                                 value = rg.find(field).text
                             except:
-                                value = ""
+                                if field == "id":
+                                    value = rg_ids.next()
+                                elif field == "master_id":
+                                    value = case_id
+                                else:
+                                    value = ""
                             sheet.add_data(value)
                         sheet.next_row()
                 else:
@@ -114,7 +124,10 @@
                         try:
                             value = case.find(field).text
                         except:
-                            value = ""
+                            if field == "id":
+                                value = case_id
+                            else:
+                                value = ""
                         sheet.add_data(value)
                     sheet.next_row()
 



More information about the Mpuls-commits mailing list