Fix overriding SEDAArchiveTransferIClonableAdapter by mistake
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Fri, 26 Jan 2018 11:48:48 +0100
changeset 3421 f0a811ee873a
parent 3419 f0e22d15953e
child 3422 074f15c857b8
Fix overriding SEDAArchiveTransferIClonableAdapter by mistake In seda, SEDAArchiveUnitIClonableAdapter inherits from SEDAArchiveTransferIClonableAdapter. So modifying rtype and skiprtypes for Transfer clone was implicitly modifying Unit clone behavior. Unit clone rtype should remain original "clone_of". Fix by registering a new adapter class for Transfer clone. Closes extranet #43776568
cubicweb_saem_ref/entities/seda.py
--- a/cubicweb_saem_ref/entities/seda.py	Mon Jan 22 17:26:58 2018 +0100
+++ b/cubicweb_saem_ref/entities/seda.py	Fri Jan 26 11:48:48 2018 +0100
@@ -55,9 +55,10 @@
     return None if agency.agency is None else 'ark:/' + agency.agency.ark
 
 
-SEDAArchiveTransferIClonableAdapter.__select__ &= is_in_state('published')
-SEDAArchiveTransferIClonableAdapter.rtype = 'new_version_of'
-SEDAArchiveTransferIClonableAdapter.skiprtypes += ('clone_of', 'used', 'generated')
+class SAEMSEDAArchiveTransferIClonableAdapter(SEDAArchiveTransferIClonableAdapter):
+    __select__ = SEDAArchiveTransferIClonableAdapter.__select__ & is_in_state('published')
+    rtype = 'new_version_of'
+    skiprtypes = SEDAArchiveTransferIClonableAdapter.skiprtypes + ('clone_of', 'used', 'generated')
 
 
 class SEDAArchiveTransfer(SEDAArchiveTransfer):
@@ -174,3 +175,10 @@
 
 class OAISEDA2RNGExportView(OAISEDAExportView):
     __regid__ = 'saem.oai.seda.2.0-rng'
+
+
+def registration_callback(vreg):
+    vreg.register_and_replace(SAEMSEDAArchiveTransferIClonableAdapter,
+                              SEDAArchiveTransferIClonableAdapter)
+    vreg.register_all(globals().values(), __name__,
+                      butclasses=(SAEMSEDAArchiveTransferIClonableAdapter,))