Changeset 82:6fe4b0e529b9

Show
Ignore:
Timestamp:
11/19/08 09:07:39 (21 months ago)
Author:
Nicolas ?vrard <nicoe@…>
Branch:
default
Message:

Correctly handle type in table cells

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • relatorio/templates/opendocument.py

    r74 r82  
    5050EtreeElement = lxml.etree.Element 
    5151 
     52def guess_type(val): 
     53    if isinstance(val, (str, unicode)): 
     54        return 'string' 
     55    elif isinstance(val, (int, float)): 
     56        return 'float' 
    5257 
    5358class OOTemplateError(genshi.template.base.TemplateSyntaxError): 
     
    260265                if parent is None or parent.tag != table_cell_tag: 
    261266                    continue 
    262                 if parent.attrib.get(office_valuetype, 'string') != 'string': 
    263                     # The grand-parent tag is a table cell we set the 
    264                     # office:value attribute of this cell 
    265                     dico = "{'%s': %s}" % (office_name, expr) 
    266                     parent.attrib[attrib_name] = dico 
    267                     parent.attrib.pop(office_name, None) 
     267 
     268                # The grand-parent tag is a table cell we should set the 
     269                # correct value and type for this cell. 
     270                dico = "{'%s': %s, '%s': guess_type(%s)}" 
     271                parent.attrib[attrib_name] = dico % (office_name, expr, 
     272                                                     office_valuetype, 
     273                                                     expr) 
     274                parent.attrib.pop(office_valuetype, None) 
     275                parent.attrib.pop(office_name, None) 
    268276 
    269277    def _handle_images(self, tree): 
     
    293301        serializer = OOSerializer(self.filepath) 
    294302        kwargs['make_href'] = ImageHref(serializer.outzip, kwargs) 
     303        kwargs['guess_type'] = guess_type 
    295304        generate_all = super(Template, self).generate(*args, **kwargs) 
    296305