[PATCH 3 of 5 seda] [profile gen] Extract a xsd_transfer_base method from xsd_transfer

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 9 17:13:50 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489073052 -3600
#      Thu Mar 09 16:24:12 2017 +0100
# Node ID 5897c8060f8ea299b200d641dbe551c757c34a78
# Parent  198ee8285875273a8a2c5694e5fe9617d9261dec
[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.

diff --git a/cubicweb_seda/entities/profile_generation.py b/cubicweb_seda/entities/profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py
+++ b/cubicweb_seda/entities/profile_generation.py
@@ -897,25 +897,11 @@ class SEDA1XSDExport(SEDA2XSDExport):
         self.xsd_transfer(root, self.entity)
         return root
 
     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)
 
     def xsd_archive(self, parent, archive_unit):
         """Append XSD elements for an archive to the given parent node."""
@@ -998,10 +984,29 @@ class SEDA1XSDExport(SEDA2XSDExport):
                 self.xsd_document(parent, au_or_bdo)
             else:
                 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)
 
         format_id = data_object.format_id
         encoding = data_object.encoding


More information about the saem-devel mailing list