Commit 7d455237 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[xsd gen] Enhance xsd_serialize function

Clearer handling of entities, drop case of date/datetime (we may only have bool
or string final values).
parent a6f4370d6f6e
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
"""cubicweb-seda entity's classes""" """cubicweb-seda entity's classes"""
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime
from lxml import etree from lxml import etree
from pyxst.xml_struct import graph_nodes from pyxst.xml_struct import graph_nodes
...@@ -353,21 +352,17 @@ def xsd_serialize(value): ...@@ -353,21 +352,17 @@ def xsd_serialize(value):
"""Return XSD value as a string depending on the type of the given `value`.""" """Return XSD value as a string depending on the type of the given `value`."""
if value is None: if value is None:
return None return None
if hasattr(value, 'labels'):
# value is a Concept
return value.labels['en']
if hasattr(value, 'id'):
# value is something in the profile which has a id
return value.id
if hasattr(value, 'eid'): if hasattr(value, 'eid'):
if value.cw_etype == 'Concept':
return value.labels['en']
if hasattr(value, 'id'):
# value is something in the profile which has a id (e.g. archive unit, data object)
return value.id
return None # intermediary entity return None # intermediary entity
if isinstance(value, bool): if isinstance(value, bool):
return 'true' if value else 'false' return 'true' if value else 'false'
if isinstance(value, (date, datetime)): assert isinstance(value, basestring), repr(value)
return value.isoformat() + 'Z' return unicode(value)
# if isinstance(value, Binary):
# return b64encode(value.getvalue)
return unicode(value) # XXX
def xsd_element_cardinality(occ, card_entity): def xsd_element_cardinality(occ, card_entity):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment