Changeset 96:ef1f4bb715a6

Show
Ignore:
Timestamp:
01/21/09 10:14:25 (19 months ago)
Author:
Ga?tan de Menten <ged@…>
Branch:
default
Message:

copy iterable in case of a rowspan'ed column repetition, so that we don't end
up with empty columns if the data is provided by a generator.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • relatorio/templates/opendocument.py

    r95 r96  
    372372                    if table_rowspan_attr in o_node_attrs: 
    373373                        rows_spanned = int(o_node_attrs[table_rowspan_attr]) 
     374 
     375                        # a_val == "target in iterable" 
     376                        target, iterable = a_val.split(' in ', 1) 
     377                        temp_var = "temp%d" % id(outermost_o_ancestor) 
     378                        # I need to get "temp_iterable = list(iterable)" 
     379                        vars = "%s = list(%s)" % (temp_var, iterable.strip()) 
     380                        # transform a_val to "target in temp_iterable" 
     381                        a_val = "%s in %s" % (target, temp_var) 
     382 
     383                        with_node = EtreeElement('{%s}with' % py_namespace, 
     384                                                 attrib={"vars": vars}, 
     385                                                 nsmap=self.namespaces) 
     386 
    374387                        # if so, we need to replace the corresponding cell on 
    375388                        # the next line (a covered-table-cell) by a duplicate 
     
    378391                        # them into the py:for node 
    379392                        row_node = outermost_o_ancestor.getparent() 
     393                        row_node.addprevious(with_node) 
     394                        rows_to_wrap = [row_node] 
     395 
    380396                        assert row_node.tag == table_row_tag 
    381397                        next_rows = row_node.itersiblings(table_row_tag) 
    382398                        for row_idx in range(rows_spanned-1): 
    383399                            next_row_node = next_rows.next() 
     400                            rows_to_wrap.append(next_row_node) 
    384401                            first = next_row_node[opening_pos] 
    385402                            last = next_row_node[closing_pos] 
     
    394411                                                    nsmap=self.namespaces) 
    395412                            wrap_nodes_between(first, last, for_node) 
     413 
     414                        for node in rows_to_wrap: 
     415                            with_node.append(node) 
    396416 
    397417                    # check if this table's headers were already processed