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

[xsd gen] Use listSchemeURI to specify URI of a scheme used as a list

and special case KeywordType which only has the listSchemeID attribute.
parent ed3ddd583511
......@@ -238,10 +238,17 @@ class SEDA2XSDExport(EntityAdapter):
def fill_element(self, xselement, target_element, extension_element, value, card_entity,
copy_attributes=False):
if getattr(value, 'cw_etype', None) == 'Concept':
self.concept_scheme_attribute(xselement, extension_element, value.scheme)
if xselement.local_name == 'KeywordType':
if value:
attrs = {'fixed': value.scheme.description or value.scheme.dc_title()}
else:
attrs = {'default': 'edition 2009'}
attrs['name'] = 'listVersionID'
attr = self.element('xsd:attribute', attributes=attrs, parent=extension_element)
elif (xselement.local_name == 'KeywordReference' and card_entity.scheme):
self.concept_scheme_attribute(xselement, extension_element, card_entity.scheme)
elif getattr(value, 'cw_etype', None) == 'Concept':
self.concept_scheme_attribute(xselement, extension_element, value.scheme)
elif copy_attributes:
for attrname, occ in xselement.attributes.items():
if attrname in ('id', 'href') or attrname.startswith(('list', 'scheme')):
......@@ -493,6 +500,6 @@ def _complex_path_target_values(entity, path):
def _xselement_scheme_attribute(xselement):
try:
return xselement.attributes['listVersionID'].target
return xselement.attributes['listSchemeURI'].target
except KeyError:
return xselement.attributes['schemeURI'].target
......@@ -92,7 +92,9 @@ def import_seda_schemes(cnx):
if not cnx.find('ConceptScheme', title=title):
print('importing', title.encode('utf-8'))
rtype_e = cnx.find('CWRType', name=rtype).one()
description = u'edition 2009' if title.startwith('SEDA') else None
scheme = cnx.create_entity('ConceptScheme', title=title,
description=description,
scheme_relation_type=rtype_e)
if etypes:
if not isinstance(etypes, tuple):
......
......@@ -245,9 +245,9 @@ class SEDAXSDExportTC(XmlTestMixin, CubicWebTC):
self.assertEqual(len(kwt), 1)
self.assertEqual(kwt[0].attrib, {'name': 'KeywordType', 'fixed': 'theme',
'minOccurs': '0'})
self.assertXSDAttributes(kwt[0],
[{'name': 'listVersionID',
'fixed': scheme.absolute_url()}])
self.assertXSDAttributes(
kwt[0],
[{'name': 'listVersionID', 'fixed': 'seda_keyword_type_to vocabulary'}])
kwr = self.xpath(profile, '//xs:element[@name="KeywordReference"]')
self.assertEqual(len(kwr), 1)
self.assertEqual(kwr[0].attrib, {'name': 'KeywordReference',
......
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