From 78b7d93de4bb0c2e65075dbc8352fcdfb8f30e5b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sun, 4 Oct 2015 14:06:00 +0200 Subject: [PATCH 2/3] fields: in export_to_xml() handle non string value for dictionnary fields (#8402) Fields using this facility must override import_from_xml() to convert the imported string value to the real type, for example a list of strings converted to CSV, must be splitted. --- wcs/fields.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wcs/fields.py b/wcs/fields.py index de83f3f..d1cedeb 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -177,7 +177,15 @@ class Field(object): el = ET.SubElement(field, attribute) if type(val) is dict: for k, v in val.items(): - ET.SubElement(el, k).text = unicode(v, charset, 'replace') + if isinstance(v, str): + text_value = unicode(v, charset, 'replace') + else: + # field having non str value + # in dictionnary field must + # overloaf import_to_xml to + # handle import + text_value = unicode(v) + ET.SubElement(el, k).text = text_value elif type(val) is list: if attribute[-1] == 's': atname = attribute[:-1] -- 2.1.4