[Checkins] SVN: zope.file/trunk/ Remove redundant firing of ObjectCreatedEvent from zope.file.upload.Upload.

Patrick Strawderman patrick at zope.com
Fri Jun 11 14:48:27 EDT 2010


Log message for revision 113367:
  Remove redundant firing of ObjectCreatedEvent from zope.file.upload.Upload.
  

Changed:
  U   zope.file/trunk/CHANGES.txt
  U   zope.file/trunk/src/zope/file/upload.py
  U   zope.file/trunk/src/zope/file/upload.txt

-=-
Modified: zope.file/trunk/CHANGES.txt
===================================================================
--- zope.file/trunk/CHANGES.txt	2010-06-11 17:51:08 UTC (rev 113366)
+++ zope.file/trunk/CHANGES.txt	2010-06-11 18:48:27 UTC (rev 113367)
@@ -5,6 +5,10 @@
 0.6.0 (unreleased)
 ------------------
 
+- Bug fix: remove duplicate firing of ObjectCreatedEvent in
+  zope.file.upload.Upload (the event is already fired in its base class,
+  zope.formlib.form.AddForm).
+
 - Move browser-related zcml to `browser.zcml` so that it easier for
   applications to exclude it.
 

Modified: zope.file/trunk/src/zope/file/upload.py
===================================================================
--- zope.file/trunk/src/zope/file/upload.py	2010-06-11 17:51:08 UTC (rev 113366)
+++ zope.file/trunk/src/zope/file/upload.py	2010-06-11 18:48:27 UTC (rev 113367)
@@ -58,8 +58,6 @@
         ob = self._create_instance(data)
         f = self.request.form["form.data"]
         updateBlob(ob, f)
-        zope.event.notify(
-            zope.lifecycleevent.ObjectCreatedEvent(ob))
         self._name = nameFinder(f)
         return ob
 

Modified: zope.file/trunk/src/zope/file/upload.txt
===================================================================
--- zope.file/trunk/src/zope/file/upload.txt	2010-06-11 17:51:08 UTC (rev 113366)
+++ zope.file/trunk/src/zope/file/upload.txt	2010-06-11 18:48:27 UTC (rev 113367)
@@ -139,3 +139,29 @@
   <html>...</html>
   <BLANKLINE>
 
+In zope.file <= 0.5.0, a redundant ObjectCreatedEvent was fired in the
+Upload view.  We'll demonstrate that this is no longer the case.
+
+  >>> import zope.component
+  >>> from zope.file.interfaces import IFile
+  >>> from zope.lifecycleevent import IObjectCreatedEvent
+
+We'll register a subscriber for IObjectCreatedEvent that simply increments
+a counter.
+
+  >>> count = 0
+  >>> def inc(*args):
+  ...   global count; count += 1
+  >>> zope.component.provideHandler(inc, (IFile, IObjectCreatedEvent))
+
+  >>> print http("""
+  ... POST /@@+/zope.file.File HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... """, form={"form.data": sio,
+  ...            "form.actions.add": "Add"}, handle_errors=False)
+  HTTP/1.1 303 ...
+
+The subscriber was called only once.
+
+  >>> print count
+  1



More information about the checkins mailing list