fix 4626:c26b4df9fc90 (#703911): use can't rely on peid since it's not an actual eid when we're creating the parent entity stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 18 Feb 2010 12:13:36 +0100
branchstable
changeset 4629 1eeef3cbf528
parent 4628 2f23148d0870
child 4630 528dee042927
fix 4626:c26b4df9fc90 (#703911): use can't rely on peid since it's not an actual eid when we're creating the parent entity
web/data/cubicweb.edition.js
web/views/autoform.py
web/views/basecontrollers.py
--- a/web/data/cubicweb.edition.js	Thu Feb 18 11:08:00 2010 +0100
+++ b/web/data/cubicweb.edition.js	Thu Feb 18 12:13:36 2010 +0100
@@ -240,12 +240,13 @@
 /*
  * makes an AJAX request to get an inline-creation view's content
  * @param peid : the parent entity eid
+ * @param petype : the parent entity type
  * @param ttype : the target (inlined) entity type
  * @param rtype : the relation type between both entities
  */
-function addInlineCreationForm(peid, ttype, rtype, role, i18nctx, insertBefore) {
+function addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) {
     insertBefore = insertBefore || getNode('add' + rtype + ':' + peid + 'link').parentNode;
-    var d = asyncRemoteExec('inline_creation_form', peid, ttype, rtype, role, i18nctx);
+    var d = asyncRemoteExec('inline_creation_form', peid, petype, ttype, rtype, role, i18nctx);
     d.addCallback(function (response) {
         var dom = getDomFromResponse(response);
         preprocessAjaxLoad(null, dom);
--- a/web/views/autoform.py	Thu Feb 18 11:08:00 2010 +0100
+++ b/web/views/autoform.py	Thu Feb 18 12:13:36 2010 +0100
@@ -169,14 +169,14 @@
     :attr etype: the entity type being created in the inline form
     """
     __regid__ = 'inline-creation'
-    __select__ = (match_kwargs('peid', 'rtype')
+    __select__ = (match_kwargs('peid', 'petype', 'rtype')
                   & specified_etype_implements('Any'))
+    _select_attrs = InlineEntityEditionFormView._select_attrs + ('petype',)
 
     @property
     def removejs(self):
         entity = self._entity()
-        ttype = self._cw.entity_from_eid(self.peid).__regid__
-        rdef = entity.e_schema.rdef(self.rtype, neg_role(self.role), ttype)
+        rdef = entity.e_schema.rdef(self.rtype, neg_role(self.role), self.petype)
         card= rdef.role_cardinality(self.role)
         # when one is adding an inline entity for a relation of a single card,
         # the 'add a new xxx' link disappears. If the user then cancel the addition,
@@ -209,7 +209,7 @@
     :attr card: the cardinality of the relation according to role of `peid`
     """
     __regid__ = 'inline-addnew-link'
-    __select__ = (match_kwargs('peid', 'rtype')
+    __select__ = (match_kwargs('peid', 'petype', 'rtype')
                   & specified_etype_implements('Any'))
 
     _select_attrs = InlineEntityCreationFormView._select_attrs + ('card',)
@@ -220,8 +220,8 @@
         divid = "addNew%s%s%s:%s" % (self.etype, self.rtype, self.role, self.peid)
         self.w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
           % divid)
-        js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % (
-            self.peid, self.etype, self.rtype, self.role, i18nctx)
+        js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s', '%s')" % (
+            self.peid, self.petype, self.etype, self.rtype, self.role, i18nctx)
         if self.pform.should_hide_add_new_relation_link(self.rtype, self.card):
             js = "toggleVisibility('%s'); %s" % (divid, js)
         __ = self._cw.pgettext
@@ -710,8 +710,9 @@
                 if self.should_display_add_new_relation_link(rschema, formviews, card):
                     addnewlink = self._cw.vreg['views'].select(
                         'inline-addnew-link', self._cw,
-                        etype=ttype, rtype=rschema, role=role,
-                        peid=self.edited_entity.eid, pform=self, card=card)
+                        etype=ttype, rtype=rschema, role=role, card=card,
+                        peid=self.edited_entity.eid,
+                        petype=self.edited_entity.e_schema, pform=self)
                     formviews.append(addnewlink)
                 allformviews += formviews
         return allformviews
@@ -771,7 +772,9 @@
         """
         yield self._cw.vreg['views'].select('inline-creation', self._cw,
                                             etype=ttype, rtype=rschema, role=role,
-                                            peid=self.edited_entity.eid, pform=self)
+                                            peid=self.edited_entity.eid,
+                                            petype=self.edited_entity.e_schema,
+                                            pform=self)
 
 
 ## default form ui configuration ##############################################
--- a/web/views/basecontrollers.py	Thu Feb 18 11:08:00 2010 +0100
+++ b/web/views/basecontrollers.py	Thu Feb 18 12:13:36 2010 +0100
@@ -383,10 +383,10 @@
 
     @check_pageid
     @xhtmlize
-    def js_inline_creation_form(self, peid, ttype, rtype, role, i18nctx):
+    def js_inline_creation_form(self, peid, petype, ttype, rtype, role, i18nctx):
         view = self._cw.vreg['views'].select('inline-creation', self._cw,
-                                         etype=ttype, peid=peid, rtype=rtype,
-                                         role=role)
+                                             etype=ttype, rtype=rtype, role=role,
+                                             peid=peid, petype=petype)
         return self._call_view(view, i18nctx=i18nctx)
 
     @jsonize