[Mpuls-commits] r5697 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 7 15:19:56 CET 2011


Author: ludwig
Date: 2011-12-07 15:19:55 +0100 (Wed, 07 Dec 2011)
New Revision: 5697

Modified:
   base/trunk/mpulsweb/lib/export.py
Log:
Issue 2620: Improvement to the XSL export.
Normal pages (without upper rg) have a master_id (the case id)
Rgs have a master_id (case id) and rg_name_id with an rg id
Rgs in rgs have the upper rg id and a rg id 


Modified: base/trunk/mpulsweb/lib/export.py
===================================================================
--- base/trunk/mpulsweb/lib/export.py	2011-12-07 10:34:36 UTC (rev 5696)
+++ base/trunk/mpulsweb/lib/export.py	2011-12-07 14:19:55 UTC (rev 5697)
@@ -120,20 +120,41 @@
                 else:
                     table_name = "master"
                     table_title = "Master"
+                prev_table_name = 'master'
+                repeat = False
                 for p in nc.pathToRoot():
                     if isinstance(p, RepeatNode):
+                        if not repeat:
+                            repeat = True
+                            prev_table_name = 'master'
+                        else:
+                            prev_table_name = table_name
                         table_name = p.getName()
                         table_title = p.getDescription()
                         repeat_groups.add(table_name)
 
                 if table_name not in table_columns:
                     table_order.append(table_name)
-                table_columns.setdefault(table_name, []).append(nc.getName())
+                if not repeat:
+                    table_columns.setdefault(table_name,
+                                             []).append(nc.getName())
+
+                elif not isinstance(nc, RepeatNode):
+                    table_columns.setdefault(table_name,[])
+                    if not table_name +"_id" in table_columns[table_name]:
+                        table_columns[table_name].append(table_name +"_id")
+                    if not prev_table_name +"_id" in table_columns[table_name]:
+                        table_columns[table_name].append(prev_table_name +"_id")
+                    table_columns[table_name].append(nc.getName())
+                else:
+                    table_columns.setdefault(table_name,
+                                             []).append(nc.getName()+"_id")
+                    table_columns[table_name].append(prev_table_name+ "_id")
                 titles[table_name] = table_title
 
         for name, columns in table_columns.iteritems():
-            extra_columns = ["id"]
-            if name in repeat_groups:
+            extra_columns = []
+            if not name in repeat_groups:
                 extra_columns.append("master_id")
             self.tables[name] = self.table_factory(titles[name],
                                                    extra_columns + columns)
@@ -149,7 +170,7 @@
             self.fill_from_node(case, case_id)
 
     def fill_from_node(self, node, node_id, parent_id=None):
-        rows = defaultdict(lambda: dict(id=node_id))
+        rows = defaultdict(lambda: dict(master_id=node_id))
 
         if parent_id is not None:
             rows[node.tag]["master_id"] = parent_id
@@ -158,7 +179,7 @@
             name = child.tag
             nc = self.meta_tree.findByName(name)
             if isinstance(nc, RepeatNode):
-                self.fill_from_node(child, self.repeat_group_ids.next(),
+                self.fill_rg_from_node(child, self.repeat_group_ids.next(),
                                     node_id)
             else:
                 table_name = self.field_name_to_table_name.get(name)
@@ -168,7 +189,42 @@
         for table_name, row in rows.iteritems():
             self.tables[table_name].append(row)
 
+    def fill_rg_from_node(self, node, node_id, case_id):
+        rows = defaultdict(lambda: dict(master_id=case_id))
+        name = node.tag
+        table_name = self.field_name_to_table_name.get(name,name)
+        rows[table_name][name + "_id"] = node_id
+        
+        self.fill_rg_children(node, node_id, rows)
 
+    def fill_inner_rg_from_node(self, node, node_id, prev_id, prev_nc):
+        rows = defaultdict(lambda: dict())
+        name = node.tag
+        table_name = self.field_name_to_table_name.get(name,name)
+        rows[table_name][name+"_id"] = node_id 
+        rows[table_name][prev_nc.getName()+ "_id"] = prev_id
+        
+        self.fill_rg_children(node, node_id, rows)
+        
+    def fill_rg_children(self, node, node_id, rows):     
+        node_name = node.tag
+        node_nc = self.meta_tree.findByName(node_name)
+        for child in node.getchildren():
+            name = child.tag
+            nc = self.meta_tree.findByName(name)
+            if isinstance(nc, RepeatNode):
+                self.fill_inner_rg_from_node(child,
+                                             self.repeat_group_ids.next(),
+                                             node_id, node_nc)
+            else:
+                table_name = self.field_name_to_table_name.get(name)
+                if table_name is not None:
+                    rows[table_name][name] = child.text
+
+        for table_name, row in rows.iteritems():
+            self.tables[table_name].append(row)
+
+        
 #
 # XLS Export
 #



More information about the Mpuls-commits mailing list