web/views/forms.py
changeset 7889 6cebeb1f386a
parent 7875 65e460690139
child 7929 900f1627b171
--- 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(':')