[PATCH 1 of 1 saem_ref] Follow api changes of the seda cube

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Mar 1 15:53:58 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488352193 -3600
#      Wed Mar 01 08:09:53 2017 +0100
# Node ID f783d861171fa2b2985cf23775d34c22e3e1da26
# Parent  38ce60fdedd73a34567763fbdb57d466277a7735
Follow api changes of the seda cube

most clone code moved back to the compound cube with more specific things
(e.g. actions) in the seda cube.

diff --git a/cubicweb_saem_ref/entities/seda.py b/cubicweb_saem_ref/entities/seda.py
--- a/cubicweb_saem_ref/entities/seda.py
+++ b/cubicweb_saem_ref/entities/seda.py
@@ -18,13 +18,13 @@
 
 from logilab.common.decorators import monkeypatch
 
 from cubicweb.predicates import is_instance, is_in_state
 
-from cubes.compound.entities import IClonableAdapter
 from cubes.oaipmh import MetadataFormat
 from cubes.oaipmh.entities import OAISetSpec
+from cubicweb_seda.entities import SEDAArchiveTransferIClonableAdapter
 from cubicweb_seda.entities.custom import SEDAArchiveTransfer
 from cubicweb_seda.entities.profile_generation import SEDA1XSDExport
 from cubicweb_seda.views import export
 
 from .. import cwuri_url
@@ -51,15 +51,13 @@ def xsd_archival_agreement(self, parent,
 @monkeypatch(SEDA1XSDExport)
 def agency_id(self, agency):
     return agency.agency.ark
 
 
-class SEDAArchiveTransferIClonableAdapter(IClonableAdapter):
-    """Cloning adapter for SEDA profiles."""
-    __select__ = IClonableAdapter.__select__ & is_in_state('published')
-    rtype = 'new_version_of'
-    skiprtypes = ()
+SEDAArchiveTransferIClonableAdapter.__select__ &= is_in_state('published')
+SEDAArchiveTransferIClonableAdapter.rtype = 'new_version_of'
+SEDAArchiveTransferIClonableAdapter.skiprtypes += ('clone_of',)
 
 
 class SEDAArchiveTransfer(SEDAArchiveTransfer):
     SEDAArchiveTransfer.fetch_attrs.append('ark')
 
diff --git a/cubicweb_saem_ref/views/clone.py b/cubicweb_saem_ref/views/clone.py
--- a/cubicweb_saem_ref/views/clone.py
+++ b/cubicweb_saem_ref/views/clone.py
@@ -25,10 +25,11 @@ from cubicweb.predicates import (adaptab
                                  is_instance, is_in_state, one_line_rset)
 from cubicweb.web import component
 from cubicweb.web.views import editforms, actions
 
 from cubicweb_seda.views.simplified import simplified_afs, simplified_pvs
+from cubicweb_seda.views.clone import SEDAArchiveTransferCloneAction
 
 
 # hide default relation components for 'new_version_of' rtype
 simplified_afs.tag_subject_of(('*', 'new_version_of', '*'), 'main', 'hidden')
 simplified_afs.tag_object_of(('*', 'new_version_of', '*'), 'main', 'hidden')
@@ -38,45 +39,12 @@ simplified_pvs.tag_object_of(('*', 'new_
 
 # life-cycle management ############################################################################
 
 # Only show clone action for SEDA profiles if no clone has been created yet
 
-class SEDAArchiveTransferCloneAction(actions.CopyAction):
-    __select__ = (actions.CopyAction.__select__ & one_line_rset()
-                  & adaptable('IClonable') & has_permission('add')
-                  & is_instance('SEDAArchiveTransfer')
-                  & ~has_related_entities('new_version_of', 'object')
-                  & is_in_state('published'))
-    title = _('new version')
-    category = 'mainactions'
-
-    def url(self):
-        entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
-        iclone = entity.cw_adapt_to('IClonable')
-        linkto = '%s:%s:%s' % (iclone.rtype, entity.eid, neg_role(iclone.role))
-        return entity.absolute_url(vid='copy', __linkto=linkto)
-
-
-actions.CopyAction.__select__ &= ~adaptable('IClonable')
-
-
-class NoWarningCopyFormView(editforms.CopyFormView):
-    """display primary entity creation form initialized with values from another
-    entity
-    """
-    __select__ = editforms.CopyFormView.__select__ & is_instance('SEDAArchiveTransfer')
-
-    def render_form(self, entity):
-        """fetch and render the form"""
-        # make a copy of entity to avoid altering the entity in the
-        # request's cache.
-        entity.complete()
-        self.newentity = copy(entity)
-        self.copying = entity
-        self.newentity.eid = self._cw.varmaker.next()
-        super(editforms.CopyFormView, self).render_form(self.newentity)
-        del self.newentity
+SEDAArchiveTransferCloneAction.__select__ &= (~has_related_entities('new_version_of', 'object')
+                                              & is_in_state('published'))
 
 
 def workflow_state(entity):
     """Return the state of the given entity."""
     return entity.cw_adapt_to('IWorkflowable').state
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,7 +1,7 @@
 pytest
 webtest
 http://hg.logilab.org/master/cubes/prov/archive/tip.tar.bz2#egg=cubicweb-prov
 http://hg.logilab.org/master/cubes/eac/archive/tip.tar.bz2#egg=cubicweb-eac
-http://hg.logilab.org/master/cubes/seda/archive/tip.tar.bz2#egg=cubicweb-seda
+http://hg.logilab.org/review/cubes/seda/archive/9920bc691cc1.tar.bz2#egg=cubicweb-seda
 http://hg.logilab.org/master/cubes/relationwidget/archive/tip.tar.bz2#egg=cubicweb-relationwidget
-http://hg.logilab.org/review/cubes/compound/archive/03180a8d8475.tar.bz2#egg=cubicweb-compound
+http://hg.logilab.org/review/cubes/compound/archive/fe2aeaad1cae.tar.bz2#egg=cubicweb-compound
diff --git a/test/unittest_entities_container.py b/test/unittest_entities_container.py
--- a/test/unittest_entities_container.py
+++ b/test/unittest_entities_container.py
@@ -80,23 +80,14 @@ class ContainerTC(CubicWebTC):
 class TreeTC(CubicWebTC):
 
     def test_seda_profile_clone(self):
         """Functional test for SEDA profile cloning."""
         with self.admin_access.repo_cnx() as cnx:
-            scheme = testutils.setup_scheme(cnx, u'Algorithms', u'md5')
-            concept = scheme.reverse_in_scheme[0]
             agent = testutils.organization_unit(cnx, u'bob', archival_roles=['deposit'])
-
-            transfer = testutils.setup_profile(
-                cnx, reverse_use_profile=agent,
-                seda_message_digest_algorithm_code_list_version=scheme)
-
-            unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(
-                transfer, cnx=cnx, title=u'hello')
-
-            testutils.create_data_object(transfer, seda_algorithm=concept)
-
+            transfer = testutils.setup_profile(cnx, reverse_use_profile=agent)
+            unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(transfer)
+            testutils.create_data_object(transfer)
             cnx.commit()
 
             transfer.cw_adapt_to('IWorkflowable').fire_transition('publish')
             cnx.commit()
 
@@ -105,18 +96,14 @@ class TreeTC(CubicWebTC):
 
             # ark and cwuri should not have been copied
             self.assertNotEqual(clone.ark, transfer.ark)
             self.assertNotEqual(clone.cwuri, transfer.cwuri)
 
-            # Everything else should have been copied
-            self.assertEqual(clone.seda_message_digest_algorithm_code_list_version[0].eid,
-                             scheme.eid)
+            # Everything else should have been copied (but other parts of the test live in the seda
+            # cube)
             self.assertEqual(clone.reverse_use_profile[0].eid,
                              agent.eid)
-            seq = clone.archive_units[0]. first_level_choice.content_sequence
-            self.assertEqual(seq.title.title, 'hello')
-            self.assertEqual(transfer.binary_data_objects[0].seda_algorithm[0].eid, concept.eid)
 
 
 if __name__ == '__main__':
     import unittest
     unittest.main()


More information about the saem-devel mailing list