[PATCH 04 of 18 seda] [entities] Order using ordering attribute when available and using the ORM

Sylvain Thenault sylvain.thenault at logilab.fr
Mon Dec 11 16:53:36 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1512569819 -3600
#      Wed Dec 06 15:16:59 2017 +0100
# Node ID 594f49bb9a268b95a5d68b96e9684c3f5afc2ef6
# Parent  41e2e0bb2020adacbe70b42e99c4e7d156c3e827
[entities] Order using ordering attribute when available and using the ORM

diff --git a/cubicweb_seda/entities/generated.py b/cubicweb_seda/entities/generated.py
--- a/cubicweb_seda/entities/generated.py
+++ b/cubicweb_seda/entities/generated.py
@@ -48,11 +48,11 @@ class SEDAArchivalAgreement(SEDAAnyEntit
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'archival_agreement', 'user_annotation'])
     value_attr = 'archival_agreement'
 
 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):
     __regid__ = 'SEDATransferRequestReplyIdentifier'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
@@ -128,21 +128,21 @@ class SEDARelationshipCodeListVersion(SE
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
 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):
     __regid__ = 'SEDADataObjectVersion'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
@@ -158,11 +158,11 @@ class SEDACompressed(SEDAAnyEntity):
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'compressed', 'user_annotation'])
     value_attr = 'compressed'
 
 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):
     __regid__ = 'SEDAServiceLevel'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'service_level', 'user_annotation'])
@@ -413,11 +413,11 @@ class SEDANeedReassessingAuthorization(S
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'need_reassessing_authorization', 'user_annotation'])
     value_attr = 'need_reassessing_authorization'
 
 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):
     __regid__ = 'SEDATitle'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'title', 'user_annotation'])
@@ -488,16 +488,16 @@ class SEDAVersion(SEDAAnyEntity):
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'version', 'user_annotation'])
     value_attr = 'version'
 
 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):
     __regid__ = 'SEDAOriginatingAgency'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
@@ -513,21 +513,21 @@ class SEDAAuthorizedAgent(SEDAAnyEntity)
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
 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):
     __regid__ = 'SEDASource'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'source', 'user_annotation'])
@@ -573,11 +573,11 @@ class SEDAEndDate(SEDAAnyEntity):
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
 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):
     __regid__ = 'SEDAPreventInheritance'
     fetch_attrs, cw_fetch_order = fetch_config(['prevent_inheritance'])
@@ -588,11 +588,11 @@ class SEDARefNonRuleId(SEDAAnyEntity):
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
 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):
     __regid__ = 'SEDACustodialHistoryFile'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
@@ -608,46 +608,46 @@ class SEDAKeywordType(SEDAAnyEntity):
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
 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):
     __regid__ = 'SEDAEventIdentifier'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
diff --git a/cubicweb_seda/xsd2entities.py b/cubicweb_seda/xsd2entities.py
--- a/cubicweb_seda/xsd2entities.py
+++ b/cubicweb_seda/xsd2entities.py
@@ -15,13 +15,14 @@
 # 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 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}'
     fetch_attrs, cw_fetch_order = fetch_config({attributes})
     value_attr = {value_attribute}
@@ -67,10 +68,12 @@ class SEDAAnyEntity(AnyEntity):
             pass
         elif mapping.attributes:
             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))
 
     def register_alt_rtype_for_rdef_mapping(self, mapping):


More information about the saem-devel mailing list