[PATCH 1 of 4 compound] Backed out changeset 03180a8d8475

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Mar 1 10:56:52 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488348644 -3600
#      Wed Mar 01 07:10:44 2017 +0100
# Node ID 4d02c64534c7e907f0464b0c87733391a483af7b
# Parent  03180a8d84755675b112f31d47a95c792d6a1060
Backed out changeset 03180a8d8475

diff --git a/i18n/en.po b/i18n/en.po
--- a/i18n/en.po
+++ b/i18n/en.po
@@ -5,8 +5,11 @@ msgstr ""
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Generated-By: pygettext.py 1.5\n"
 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
 
+msgid "clone"
+msgstr ""
+
 #, python-format
 msgid "clone of entity #%d created"
 msgstr ""
diff --git a/i18n/fr.po b/i18n/fr.po
--- a/i18n/fr.po
+++ b/i18n/fr.po
@@ -5,8 +5,11 @@ msgstr ""
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Generated-By: pygettext.py 1.5\n"
 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
 
+msgid "clone"
+msgstr "cloner"
+
 #, python-format
 msgid "clone of entity #%d created"
 msgstr "un clone de l'entité #%d a été crée"
diff --git a/test/test_compound.py b/test/test_compound.py
--- a/test/test_compound.py
+++ b/test/test_compound.py
@@ -17,10 +17,11 @@
 
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubes.compound import CompositeGraph
 from cubes.compound.entities import IClonableAdapter, copy_entity
+from cubes.compound.views import CloneAction
 
 
 def sort_keys(dic):
     return dict((k, sorted(v)) for k, v in dic.items())
 
@@ -361,10 +362,18 @@ class CloneTC(CubicWebTC):
             rset = cnx.execute(
                 'Any X WHERE X name "bobby", X account AC, X biography B,'
                 '            B event E, E is Event, B event A, A narrated_by X')
             self.assertTrue(rset)
 
+    def test_clone_action(self):
+        with self.admin_access.web_request() as req:
+            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)
+
     @staticmethod
     def _clone_setup(cnx):
         """Setup a graph of entities to be cloned."""
         agent = cnx.create_entity('Agent', name=u'bob')
         cnx.create_entity('OnlineAccount', reverse_account=agent)
diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -13,18 +13,36 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-compound views/forms/actions/components for web ui"""
 
+from cubicweb import _, neg_role
 from cubicweb.web import Redirect
-from cubicweb.predicates import adaptable, match_form_params
+from cubicweb.predicates import (one_line_rset, adaptable, has_permission,
+                                 match_form_params)
 from cubicweb.web.controller import Controller
-from cubicweb.web.views import ibreadcrumbs
+from cubicweb.web.views import actions, ibreadcrumbs
 
 from cubes.compound.entities import copy_entity
 
 
+class CloneAction(actions.CopyAction):
+    """Just a copy action (copy is handled by edit controller below) named 'clone'."""
+    __select__ = (actions.CopyAction.__select__ & one_line_rset() &
+                  adaptable('IClonable') & has_permission('add'))
+    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)
+
+
+actions.CopyAction.__select__ &= ~adaptable('IClonable')
+
+
 class CloneController(Controller):
     """Controller handling cloning of the original entity (with `eid` passed
     in form parameters). Redirects to the cloned entity primary view.
     """
     __regid__ = 'compound.clone'


More information about the saem-devel mailing list