Added 'locate' call in creation forms to avoid NotYet exception when registering contents
authorThierry Florac <thierry.florac@onf.fr>
Fri, 20 Mar 2015 17:29:54 +0100
changeset 9 c41a835fc348
parent 8 299f3f455f4f
child 10 674e6e01ea54
Added 'locate' call in creation forms to avoid NotYet exception when registering contents
src/pyams_form/form.py
--- a/src/pyams_form/form.py	Wed Mar 11 11:58:00 2015 +0100
+++ b/src/pyams_form/form.py	Fri Mar 20 17:29:54 2015 +0100
@@ -43,6 +43,7 @@
 from zope.component import queryUtility
 from zope.interface import implementer, alsoProvides, Interface
 from zope.lifecycleevent import Attributes, ObjectCreatedEvent
+from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
 
 from pyams_form import _
@@ -264,8 +265,12 @@
 
     def createAndAdd(self, data):
         registry = self.request.registry
+        # create object
         object = self.create(data)
         registry.notify(ObjectCreatedEvent(object))
+        # set parent temporarily to avoid NotYet exceptions
+        locate(object, self.context)
+        # update object properties before adding it
         self.update_content(object, data)
         self.add(object)
         registry.notify(FormObjectCreatedEvent(object, self))