Updated AddForm to notify events only when created object was not none
authorThierry Florac <thierry.florac@onf.fr>
Wed, 15 Apr 2015 15:01:43 +0200
changeset 11 ffebc76eaaa3
parent 10 674e6e01ea54
child 12 4ccb93fcde8e
Updated AddForm to notify events only when created object was not none
src/pyams_form/form.py
--- a/src/pyams_form/form.py	Wed Apr 15 15:00:56 2015 +0200
+++ b/src/pyams_form/form.py	Wed Apr 15 15:01:43 2015 +0200
@@ -267,13 +267,14 @@
         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))
+        if object is not None:
+            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))
         return object