[entities] Order using ordering attribute when available and using the ORM
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 06 Dec 2017 15:16:59 +0100
changeset 2899 ed666cbea6af
parent 2898 8bd8b3533dec
child 2900 e0e34c11185e
[entities] Order using ordering attribute when available and using the ORM
cubicweb_seda/entities/generated.py
cubicweb_seda/xsd2entities.py
--- a/cubicweb_seda/entities/generated.py	Wed Dec 06 15:13:23 2017 +0100
+++ b/cubicweb_seda/entities/generated.py	Wed Dec 06 15:16:59 2017 +0100
@@ -50,7 +50,7 @@
 
 class SEDARelatedTransferReference(SEDAAnyEntity):
     __regid__ = 'SEDARelatedTransferReference'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDATransferRequestReplyIdentifier(SEDAAnyEntity):
@@ -130,17 +130,17 @@
 
 class SEDABinaryDataObject(SEDAAnyEntity):
     __regid__ = 'SEDABinaryDataObject'
-    fetch_attrs, cw_fetch_order = fetch_config(['filename', 'user_cardinality', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'filename', 'user_cardinality', 'user_annotation'])
     value_attr = None
 
 class SEDAPhysicalDataObject(SEDAAnyEntity):
     __regid__ = 'SEDAPhysicalDataObject'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'user_annotation'])
     value_attr = None
 
 class SEDARelationship(SEDAAnyEntity):
     __regid__ = 'SEDARelationship'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDADataObjectVersion(SEDAAnyEntity):
@@ -160,7 +160,7 @@
 
 class SEDAArchiveUnit(SEDAAnyEntity):
     __regid__ = 'SEDAArchiveUnit'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'user_annotation'])
     value_attr = None
 
 class SEDAServiceLevel(SEDAAnyEntity):
@@ -415,7 +415,7 @@
 
 class SEDADataObjectReference(SEDAAnyEntity):
     __regid__ = 'SEDADataObjectReference'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDATitle(SEDAAnyEntity):
@@ -490,12 +490,12 @@
 
 class SEDATag(SEDAAnyEntity):
     __regid__ = 'SEDATag'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'tag', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'tag', 'user_annotation'])
     value_attr = 'tag'
 
 class SEDAKeyword(SEDAAnyEntity):
     __regid__ = 'SEDAKeyword'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'keyword_content', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'keyword_content', 'user_annotation'])
     value_attr = 'keyword_content'
 
 class SEDAOriginatingAgency(SEDAAnyEntity):
@@ -515,17 +515,17 @@
 
 class SEDAWriter(SEDAAnyEntity):
     __regid__ = 'SEDAWriter'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDAAddressee(SEDAAnyEntity):
     __regid__ = 'SEDAAddressee'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDARecipient(SEDAAnyEntity):
     __regid__ = 'SEDARecipient'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDASource(SEDAAnyEntity):
@@ -575,7 +575,7 @@
 
 class SEDAEvent(SEDAAnyEntity):
     __regid__ = 'SEDAEvent'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDAPreventInheritance(SEDAAnyEntity):
@@ -590,7 +590,7 @@
 
 class SEDACustodialHistoryItem(SEDAAnyEntity):
     __regid__ = 'SEDACustodialHistoryItem'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'custodial_history_item', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'custodial_history_item', 'user_annotation'])
     value_attr = 'custodial_history_item'
 
 class SEDACustodialHistoryFile(SEDAAnyEntity):
@@ -610,42 +610,42 @@
 
 class SEDASpatial(SEDAAnyEntity):
     __regid__ = 'SEDASpatial'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'spatial', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'spatial', 'user_annotation'])
     value_attr = 'spatial'
 
 class SEDATemporal(SEDAAnyEntity):
     __regid__ = 'SEDATemporal'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'temporal', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'temporal', 'user_annotation'])
     value_attr = 'temporal'
 
 class SEDAJuridictional(SEDAAnyEntity):
     __regid__ = 'SEDAJuridictional'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'juridictional', 'user_annotation'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality', 'juridictional', 'user_annotation'])
     value_attr = 'juridictional'
 
 class SEDAIsVersionOf(SEDAAnyEntity):
     __regid__ = 'SEDAIsVersionOf'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDAReplaces(SEDAAnyEntity):
     __regid__ = 'SEDAReplaces'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDARequires(SEDAAnyEntity):
     __regid__ = 'SEDARequires'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDAIsPartOf(SEDAAnyEntity):
     __regid__ = 'SEDAIsPartOf'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDAReferences(SEDAAnyEntity):
     __regid__ = 'SEDAReferences'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    fetch_attrs, cw_fetch_order = fetch_config(['ordering', 'user_cardinality'])
     value_attr = None
 
 class SEDAEventIdentifier(SEDAAnyEntity):
--- a/cubicweb_seda/xsd2entities.py	Wed Dec 06 15:13:23 2017 +0100
+++ b/cubicweb_seda/xsd2entities.py	Wed Dec 06 15:16:59 2017 +0100
@@ -17,9 +17,10 @@
 
 import json
 
-from xsd2yams import CodeGenerator
+from xsd2yams import MULTIPLE_CHILDREN, CodeGenerator
 from xsd2uicfg import ordered_attributes
 
+MULTIPLE_ETYPES = set(etype for etype, _ in MULTIPLE_CHILDREN)
 
 TEMPLATE = '''class {etype}(SEDAAnyEntity):
     __regid__ = '{etype}'
@@ -69,6 +70,8 @@
             value_attribute = next(iter(mapping.attributes))
         elif mapping.cards and len(mapping.cards) > 1:
             attributes = ['user_cardinality']
+        if mapping.etype in MULTIPLE_ETYPES:
+            attributes.insert(0, 'ordering')
         return TEMPLATE.format(etype=mapping.etype,
                                attributes=attributes,
                                value_attribute=repr(value_attribute))