[profile gen] Extract a xsd_transfer_base method from xsd_transfer
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 09 Mar 2017 16:24:12 +0100
changeset 2472 5897c8060f8e
parent 2471 198ee8285875
child 2473 6c5b63064379
[profile gen] Extract a xsd_transfer_base method from xsd_transfer So we'll be able in later cset to override xsd_transfer in SEDA 0.2 export without having to much duplicated code.
cubicweb_seda/entities/profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py	Thu Mar 09 16:22:57 2017 +0100
+++ b/cubicweb_seda/entities/profile_generation.py	Thu Mar 09 16:24:12 2017 +0100
@@ -899,21 +899,7 @@
 
     def xsd_transfer(self, parent, archive_transfer):
         """Append XSD elements for the archive transfer to the given parent node."""
-        transfer_node = self.element_schema(parent, 'ArchiveTransfer',
-                                            documentation=archive_transfer.title,
-                                            xsd_attributes=[XAttr('Id', 'xsd:ID')])
-        for comment in archive_transfer.comments:
-            self.element_schema(transfer_node, 'Comment', 'udt:TextType',
-                                fixed_value=comment.comment,
-                                cardinality=comment.user_cardinality,
-                                documentation=comment.user_annotation,
-                                xsd_attributes=[XAttr('languageID', 'xsd:language')])
-        self.element_schema(transfer_node, 'Date', 'udt:DateTimeType')
-        self.element_schema(transfer_node, 'TransferIdentifier', 'qdt:ArchivesIDType',
-                            xsd_attributes=self.xsd_attributes_scheme())
-        for agency_type in ('TransferringAgency', 'ArchivalAgency'):
-            self.xsd_agency(transfer_node, agency_type)
-
+        transfer_node = self.xsd_transfer_base(parent, archive_transfer)
         for archive_unit in archive_transfer.archive_units:
             self.xsd_archive(transfer_node, archive_unit)
 
@@ -1000,6 +986,25 @@
                 assert au_or_bdo.cw_etype == 'SEDAArchiveUnit'
                 self.xsd_archive_object(parent, au_or_bdo)
 
+    def xsd_transfer_base(self, parent, archive_transfer):
+        """Create ArchiveTransfer element and add child which are common in 0.2 and 1.0.
+        """
+        transfer_node = self.element_schema(parent, 'ArchiveTransfer',
+                                            documentation=archive_transfer.title,
+                                            xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        for comment in archive_transfer.comments:
+            self.element_schema(transfer_node, 'Comment', 'udt:TextType',
+                                fixed_value=comment.comment,
+                                cardinality=comment.user_cardinality,
+                                documentation=comment.user_annotation,
+                                xsd_attributes=[XAttr('languageID', 'xsd:language')])
+        self.element_schema(transfer_node, 'Date', 'udt:DateTimeType')
+        self.element_schema(transfer_node, 'TransferIdentifier', 'qdt:ArchivesIDType',
+                            xsd_attributes=self.xsd_attributes_scheme())
+        for agency_type in ('TransferringAgency', 'ArchivalAgency'):
+            self.xsd_agency(transfer_node, agency_type)
+        return transfer_node
+
     def xsd_attachment(self, parent, data_object):
         _safe_concept = partial(_safe_concept_value, concepts_language=self.concepts_language)