Changeset 159:6e130c152965

Show
Ignore:
Timestamp:
01/21/10 04:22:17 (6 months ago)
Author:
C?dric Krier <ced@…>
Branch:
default
Message:

Update py:attrs attributes in opendocument

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • CHANGES

    r154 r159  
     1 * Update py:attrs attributes in opendocument 
     2 
    130.5.3 - 20100110 
    24 * Escape elements values in opendocument template 
  • relatorio/templates/opendocument.py

    r153 r159  
    186186 
    187187 
     188def update_py_attrs(node, value): 
     189    """An helper function to update py_attrs of a node. 
     190    """ 
     191    if not value: 
     192        return 
     193    py_attrs_attr = '{%s}attrs' % GENSHI_URI 
     194    if not py_attrs_attr in node.attrib: 
     195        node.attrib[py_attrs_attr] = value 
     196    else: 
     197        node.attrib[py_attrs_attr] = \ 
     198                "(lambda x, y: x.update(y) or x)(%s or {}, %s or {})" % \ 
     199                (node.attrib[py_attrs_attr], value) 
     200 
     201 
    188202class Template(MarkupTemplate): 
    189203 
     
    417431                # correct value and type for this cell. 
    418432                dico = "{'%s': %s, '%s': __relatorio_guess_type(%s)}" 
    419                 parent.attrib[py_attrs_attr] = dico % (office_name, expr, 
    420                                                        office_valuetype, expr) 
     433                update_py_attrs(parent, dico % 
     434                        (office_name, expr, office_valuetype, expr)) 
    421435                parent.attrib.pop(office_valuetype, None) 
    422436                parent.attrib.pop(office_name, None) 
     
    448462        # operations, but a unique id within the table is required 
    449463        # to support nested column repetition 
    450         ancestor.attrib[py_attrs_attr] = \ 
    451             "__relatorio_reset_col_count(%d)" % loop_id 
     464        update_py_attrs(ancestor, "__relatorio_reset_col_count(%d)" % loop_id) 
    452465 
    453466        # 2) add increment code (through a py:attrs attribute) on 
     
    456469        enclosed_cell = outer_o_node.getnext() 
    457470        assert enclosed_cell.tag == '{%s}table-cell' % table_namespace 
    458         enclosed_cell.attrib[py_attrs_attr] = \ 
    459             "__relatorio_inc_col_count(%d)" % loop_id 
     471        update_py_attrs(enclosed_cell, "__relatorio_inc_col_count(%d)" % 
     472                loop_id) 
    460473 
    461474        # 3) add "store count" code as a py:replace node, as the