[PATCH 6 of 8 compound V2] Backport NoWarningCopyFormView from saem_ref

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


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488530798 -3600
#      Fri Mar 03 09:46:38 2017 +0100
# Node ID 84b9d6848eb78340105983bfb2ba858620f476d2
# Parent  2b34f5d03582d30c869dd3a22cdb393487399322
Backport NoWarningCopyFormView from saem_ref

so any clonable entity relying on the copy form won't have the 'swallow copy'
warning message.

diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -13,16 +13,17 @@
 #
 # 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 copy import copy
+
 from cubicweb import _, neg_role
 from cubicweb.web import Redirect
-from cubicweb.predicates import (one_line_rset, adaptable, has_permission,
-                                 match_form_params)
+from cubicweb.predicates import adaptable, has_permission, match_form_params, one_line_rset
 from cubicweb.web.controller import Controller
-from cubicweb.web.views import actions, ibreadcrumbs
+from cubicweb.web.views import actions, editforms, ibreadcrumbs
 
 from cubes.compound.entities import copy_entity
 
 
 def linkto_clone_url_params(entity):
@@ -52,10 +53,28 @@ class CloneAction(actions.CopyAction):
 # In any case IClonable entities want default copy disabled since it wont handle
 # composite relations by default.
 actions.CopyAction.__select__ &= ~adaptable('IClonable')
 
 
+class NoWarningCopyFormView(editforms.CopyFormView):
+    """Display primary entity creation form initialized with values from another
+    entity, but avoiding cubicweb default 'this is only a shallow copy' message.
+    """
+    __select__ = editforms.CopyFormView.__select__ & adaptable('ICloneable')
+
+    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
+
+
 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