[linkto] test for main form should be done in the link_to dictionary computation, else we may get erroneous values for sub-forms
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 29 Sep 2011 14:07:37 +0200
changeset 7889 6cebeb1f386a
parent 7882 974a8653aede
child 7894 ad0eeb0f7a8d
[linkto] test for main form should be done in the link_to dictionary computation, else we may get erroneous values for sub-forms
web/views/forms.py
--- a/web/views/forms.py	Wed Sep 28 14:33:43 2011 +0200
+++ b/web/views/forms.py	Thu Sep 29 14:07:37 2011 +0200
@@ -386,15 +386,12 @@
             self.add_hidden('_cwmsgid', msgid)
 
     def add_linkto_hidden(self):
-        '''add the __linkto hidden field used to directly attach the new object
+        """add the __linkto hidden field used to directly attach the new object
         to an existing other one when the relation between those two is not
         already present in the form.
-        Warning: this method must be called only when all form fields are setup'''
-        # if current form is not the main form, exit immediately
-        try:
-            self.field_by_name('__maineid')
-        except form.FieldNotFound:
-            return
+
+        Warning: this method must be called only when all form fields are setup
+        """
         for (rtype, role), eids in self.linked_to.iteritems():
             # if the relation is already setup by a form field, do not add it
             # in a __linkto hidden to avoid setting it twice in the controller
@@ -411,6 +408,11 @@
     @property
     @cached
     def linked_to(self):
+        # if current form is not the main form, exit immediately
+        try:
+            self.field_by_name('__maineid')
+        except form.FieldNotFound:
+            return {}
         linked_to = {}
         for linkto in self._cw.list_form_param('__linkto'):
             ltrtype, eid, ltrole = linkto.split(':')