[PATCH 1 of 8 compound V2] Backed out changeset 03180a8d8475

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 3 09:49:00 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 3a080ed72f558727c9e7b132025fc77bad50c934
# Parent  5b0cf134ad26cf13349e8d0e2a9dd46f9613962e
Backed out changeset 03180a8d8475

the original intent was to avoid having an automatic 'clone' action appearing in
the UI because some type was adaptable to IClonable. While this is still
desirable, keeping some generic UI tweaks useful to those activating the action
will be better then dropping everything at once.

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