def to_xml(self): xData = ElementTree.Element(self.data_type.tag) for attribute in self.data_type.item_attributes: try: xData.attrib[attribute] = serialize(self.item_attributes[attribute]) except KeyError as e: # This should never occur, buf if it does, the OTA restore on mobile will fail and # this error would have been raised and email-logged. raise FixtureTypeCheckError( "Table with tag %s has an item with id %s that doesn't have an attribute as defined in its types definition" % (self.data_type.tag, self.get_id) ) for field in self.data_type.fields: escaped_field_name = clean_fixture_field_name(field.field_name) if not self.fields.has_key(field.field_name): xField = ElementTree.SubElement(xData, escaped_field_name) xField.text = "" else: for field_with_attr in self.fields[field.field_name].field_list: xField = ElementTree.SubElement(xData, escaped_field_name) xField.text = serialize(field_with_attr.field_value) for attribute in field_with_attr.properties: val = field_with_attr.properties[attribute] xField.attrib[attribute] = serialize(val) return xData
def to_xml(self): def _serialize(val): if isinstance(val, (int, Decimal)): return unicode(val) else: return val if val is not None else "" xData = ElementTree.Element(self.data_type.tag) for attribute in self.data_type.item_attributes: try: xData.attrib[attribute] = _serialize( self.item_attributes[attribute]) except KeyError as e: # This should never occur, buf if it does, the OTA restore on mobile will fail and # this error would have been raised and email-logged. raise FixtureTypeCheckError( "Table with tag %s has an item with id %s that doesn't have an attribute as defined in its types definition" % (self.data_type.tag, self.get_id)) for field in self.data_type.fields: escaped_field_name = clean_fixture_field_name(field.field_name) if not self.fields.has_key(field.field_name): xField = ElementTree.SubElement(xData, escaped_field_name) xField.text = "" else: for field_with_attr in self.fields[ field.field_name].field_list: xField = ElementTree.SubElement(xData, escaped_field_name) xField.text = _serialize(field_with_attr.field_value) for attribute in field_with_attr.properties: val = field_with_attr.properties[attribute] xField.attrib[attribute] = _serialize(val) return xData