[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ Fixed to generate a modified event if some attributes get set after an

Jim Fulton jim at zope.com
Sun Aug 29 16:55:10 EDT 2004


Log message for revision 27338:
  Fixed to generate a modified event if some attributes get set after an
  object is added.
  


Changed:
  U   Zope3/trunk/src/zope/app/form/browser/add.py
  U   Zope3/trunk/src/zope/app/form/browser/tests/test_add.py


-=-
Modified: Zope3/trunk/src/zope/app/form/browser/add.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/add.py	2004-08-29 20:54:22 UTC (rev 27337)
+++ Zope3/trunk/src/zope/app/form/browser/add.py	2004-08-29 20:55:10 UTC (rev 27338)
@@ -21,7 +21,8 @@
 
 from zope.app import zapi
 from zope.event import notify
-from zope.app.event.objectevent import ObjectCreatedEvent
+
+from zope.app.event.objectevent import ObjectCreatedEvent, ObjectModifiedEvent
 from zope.app.form.utility import setUpWidgets, getWidgetsData
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.form.interfaces import IInputWidget, WidgetsError
@@ -119,6 +120,10 @@
                     except ValidationError:
                         errors.append(sys.exc_info()[1])
 
+            # We've modified the object, so we need to pubish an
+            # object-modified event:
+            notify(ObjectModifiedEvent(content))
+
         if errors:
             raise WidgetsError(*errors)
 

Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_add.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_add.py	2004-08-29 20:54:22 UTC (rev 27337)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_add.py	2004-08-29 20:55:10 UTC (rev 27338)
@@ -25,6 +25,8 @@
 from zope.schema import TextLine, accessors
 from zope.component import getView
 
+from zope.app.event.tests.placelesssetup import getEvents
+from zope.app.event.interfaces import IObjectCreatedEvent, IObjectModifiedEvent
 from zope.app.form.browser.add import AddViewFactory, AddView
 from zope.app.form.browser.metaconfigure import AddFormDirective
 from zope.app.container.interfaces import IAdding
@@ -129,13 +131,23 @@
 
     def test_add_error_handling(self):
         # cannot use a field in arguments if it is not mentioned in fields
-        self.assertRaises(ValueError, self._invoke_add, fields="first email getfoo extra1".split())
-        # cannot use a field in keyword_arguments if it is not mentioned in fields
-        self.assertRaises(ValueError, self._invoke_add, fields="first last getfoo extra1".split())
+        self.assertRaises(ValueError, self._invoke_add,
+                          fields="first email getfoo extra1".split())
+
+        # cannot use a field in keyword_arguments if it is not
+        # mentioned in fields
+
+        self.assertRaises(ValueError, self._invoke_add,
+                          fields="first last getfoo extra1".split())
+
         # cannot use a field in set_before_add if it is not mentioned in fields
-        self.assertRaises(ValueError, self._invoke_add, fields="first last email extra1".split())
+        self.assertRaises(ValueError, self._invoke_add,
+                          fields="first last email extra1".split())
+
         # cannot use a field in set_after_add if it is not mentioned in fields
-        self.assertRaises(ValueError, self._invoke_add, fields="first last email getfoo".split())
+        self.assertRaises(ValueError, self._invoke_add,
+                          fields="first last email getfoo".split())
+
         # cannot use an optional field in arguments
         self.assertRaises(ValueError, self._invoke_add, arguments=["extra2"])
 
@@ -243,6 +255,8 @@
         self.assertEqual(adding.ob.extra2, "extra2")
         self.assertEqual(adding.ob.name, "foo")
         self.assertEqual(adding.ob.address, "aa")
+        self.assertEqual(len(getEvents(IObjectCreatedEvent)), 1)
+        self.assertEqual(len(getEvents(IObjectModifiedEvent)), 1)
 
     def test_createAndAdd_w_adapter(self):
 



More information about the Zope3-Checkins mailing list