Commit e60554e0 authored by Yann Voté's avatar Yann Voté
Browse files

[code gen] Generate a mapping SEDAAlt... -> child_rtype

This mapping will be useful to check that a choice is not empty, that is its
child relation is always present.

Related to #12515331.
parent 922e034e4ce0
......@@ -727,3 +727,66 @@ class SEDARelationshipCodeListVersion(AnyEntity):
fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
value_attr = None
CHOICE_RTYPE = {
'SEDAAltAccessRulePreventInheritance': [
'seda_prevent_inheritance',
'seda_ref_non_rule_id_from'
],
'SEDAAltAppraisalRulePreventInheritance': [
'seda_prevent_inheritance',
'seda_ref_non_rule_id_from'
],
'SEDAAltArchiveUnitArchiveUnitRefId': [
'seda_archive_unit_ref_id_from'
],
'SEDAAltBinaryDataObjectAttachment': [
'seda_attachment',
'seda_uri'
],
'SEDAAltClassificationRulePreventInheritance': [
'seda_prevent_inheritance',
'seda_ref_non_rule_id_from'
],
'SEDAAltDisseminationRulePreventInheritance': [
'seda_prevent_inheritance',
'seda_ref_non_rule_id_from'
],
'SEDAAltIsPartOfArchiveUnitRefId': [
'seda_archive_unit_ref_id_from',
'seda_repository_archive_unit_pid',
'seda_repository_object_pid',
'seda_data_object_reference'
],
'SEDAAltIsVersionOfArchiveUnitRefId': [
'seda_archive_unit_ref_id_from',
'seda_repository_archive_unit_pid',
'seda_repository_object_pid',
'seda_data_object_reference'
],
'SEDAAltReferencesArchiveUnitRefId': [
'seda_archive_unit_ref_id_from',
'seda_data_object_reference',
'seda_repository_archive_unit_pid',
'seda_repository_object_pid'
],
'SEDAAltReplacesArchiveUnitRefId': [
'seda_archive_unit_ref_id_from',
'seda_repository_archive_unit_pid',
'seda_repository_object_pid',
'seda_data_object_reference'
],
'SEDAAltRequiresArchiveUnitRefId': [
'seda_archive_unit_ref_id_from',
'seda_repository_archive_unit_pid',
'seda_repository_object_pid',
'seda_data_object_reference'
],
'SEDAAltReuseRulePreventInheritance': [
'seda_prevent_inheritance',
'seda_ref_non_rule_id_from'
],
'SEDAAltStorageRulePreventInheritance': [
'seda_prevent_inheritance',
'seda_ref_non_rule_id_from'
]
}
......@@ -15,6 +15,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Generate CubicWeb's entities from XSD file"""
import json
from xsd2yams import CodeGenerator
from xsd2uicfg import ordered_attributes
......@@ -30,10 +32,15 @@ class EntitiesGenerator(CodeGenerator):
def _generate(self, mapping, stream):
stream.write('from cubicweb.entities import AnyEntity, fetch_config\n\n')
self.altetype2rtype = {} # registry of rtype to children elements for all choices
for mapping_element in mapping.ordered:
self._callback('register_alt_rtype_for', mapping_element)
eclass_code = self._callback('entity_class_for', mapping_element)
if eclass_code:
stream.write(eclass_code + '\n')
stream.write(u'CHOICE_RTYPE = ') # Write the registry as a constant
stream.write(json.dumps(self.altetype2rtype, sort_keys=True, indent=2,
separators=(',', ': ')).replace('"', "'") + '\n')
def entity_class_for_e_type_mapping(self, mapping):
attributes = ordered_attributes(mapping)
......@@ -52,6 +59,12 @@ class EntitiesGenerator(CodeGenerator):
attributes=attributes,
value_attribute=repr(value_attribute))
def register_alt_rtype_for_rdef_mapping(self, mapping):
objtypes = mapping.objtypes
for objtype in objtypes:
if objtype.startswith('SEDAAlt') and mapping.composite == 'object':
self.altetype2rtype.setdefault(objtype, []).append(mapping.rtype)
if __name__ == '__main__':
EntitiesGenerator.main()
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