Skip to content
Snippets Groups Projects
Commit 3e18380a64c4 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Backport NoWarningCopyFormView from saem_ref

so any clonable entity relying on the copy form won't have the 'swallow copy'
warning message.
parent 5628127b9da5
No related branches found
No related tags found
No related merge requests found
......@@ -15,5 +15,7 @@
# 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
......@@ -18,5 +20,4 @@
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
......@@ -22,5 +23,5 @@
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
......@@ -54,6 +55,24 @@
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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment