[inlined forms] nicer add_hiddens implementation relying on standard entity forms handling stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 30 Sep 2009 17:32:03 +0200
branchstable
changeset 3532 df045bc51d00
parent 3531 c095f5f54873
child 3533 88ceed15a3d3
[inlined forms] nicer add_hiddens implementation relying on standard entity forms handling
web/views/editforms.py
--- a/web/views/editforms.py	Wed Sep 30 16:34:43 2009 +0200
+++ b/web/views/editforms.py	Wed Sep 30 17:32:03 2009 +0200
@@ -16,6 +16,7 @@
 from logilab.mtconverter import xml_escape
 from logilab.common.decorators import cached
 
+from cubicweb import neg_role
 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
                                 specified_etype_implements, yes)
 from cubicweb.utils import make_uid
@@ -501,15 +502,12 @@
             counter=self.req.data[countkey], **kwargs))
 
     def add_hiddens(self, form, entity):
-        # to ease overriding (see cubes.vcsfile.views.forms for instance)
-        if self.keep_entity(form, entity):
-            if entity.has_eid():
-                rval = entity.eid
-            else:
-                rval = INTERNAL_FIELD_VALUE
-            form.form_add_hidden('edit%s-%s:%s' % (self.role[0], self.rtype, self.peid), rval)
-        form.form_add_hidden(name='%s:%s' % (self.rtype, self.peid), value=entity.eid,
-                             id='rel-%s-%s-%s'  % (self.peid, self.rtype, entity.eid))
+        """to ease overriding (see cubes.vcsfile.views.forms for instance)"""
+        iid = 'rel-%s-%s-%s' % (self.peid, self.rtype, entity.eid)
+        form.form_add_hidden(name=self.rtype, value=self.peid,
+                             # role is the for parent entity, we want the role
+                             # of the inlined entity
+                             role=neg_role(self.role), eidparam=True, id=iid)
 
     def keep_entity(self, form, entity):
         if not entity.has_eid():