[PATCH 4 of 8 compound V2] Extract part of CloneAction.url into a linkto_clone_url_params function

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 3 09:49:03 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488530727 -3600
#      Fri Mar 03 09:45:27 2017 +0100
# Node ID e6088269106fce39287c4c57146412a99ee64b26
# Parent  41dcce2866f1932b1b2c231494d6832572ef9852
Extract part of CloneAction.url into a linkto_clone_url_params function

and test it.

diff --git a/test/test_compound.py b/test/test_compound.py
--- a/test/test_compound.py
+++ b/test/test_compound.py
@@ -369,10 +369,11 @@ class CloneTC(CubicWebTC):
             entity = req.create_entity('Agent', name=u'bob')
             req.cnx.commit()
             action = self.vreg['actions'].select('copy', req,
                                                  rset=entity.as_rset())
             self.assertIsInstance(action, CloneAction)
+            self.assertIn('clone_of', action.url())
 
     @staticmethod
     def _clone_setup(cnx):
         """Setup a graph of entities to be cloned."""
         agent = cnx.create_entity('Agent', name=u'bob')
diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -23,10 +23,16 @@ from cubicweb.web.controller import Cont
 from cubicweb.web.views import actions, ibreadcrumbs
 
 from cubes.compound.entities import copy_entity
 
 
+def linkto_clone_url_params(entity):
+    iclone = entity.cw_adapt_to('IClonable')
+    linkto = '%s:%s:%s' % (iclone.rtype, entity.eid, neg_role(iclone.role))
+    return {'__linkto': linkto}
+
+
 class CloneAction(actions.CopyAction):
     """Abstract clone action of ICloneable entities.
 
     Simply inherit from it with a specific selector if you want to activate it.
     The action will link to the copy form with shallow copy message disabled and
@@ -38,13 +44,11 @@ class CloneAction(actions.CopyAction):
                   & adaptable('IClonable'))
     title = _('clone')
 
     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)
+        return entity.absolute_url(vid='copy', **linkto_clone_url_params(entity))
 
 
 # In any case IClonable entities want default copy disabled since it wont handle
 # composite relations by default.
 actions.CopyAction.__select__ &= ~adaptable('IClonable')


More information about the saem-devel mailing list