[Zope3-checkins] SVN: Zope3/trunk/src/zope/ fire events before
updating viewlets in manager
Bernd Dorn
bernd.dorn at lovelysystems.com
Wed Apr 18 05:24:09 EDT 2007
Log message for revision 74234:
fire events before updating viewlets in manager
Changed:
U Zope3/trunk/src/zope/contentprovider/interfaces.py
U Zope3/trunk/src/zope/viewlet/README.txt
U Zope3/trunk/src/zope/viewlet/manager.py
-=-
Modified: Zope3/trunk/src/zope/contentprovider/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/contentprovider/interfaces.py 2007-04-18 05:34:45 UTC (rev 74233)
+++ Zope3/trunk/src/zope/contentprovider/interfaces.py 2007-04-18 09:24:06 UTC (rev 74234)
@@ -21,6 +21,7 @@
import zope.interface
from zope.tales import interfaces
from zope.publisher.interfaces import browser
+from zope.component.interfaces import ObjectEvent, IObjectEvent
class IUpdateNotCalled(zope.interface.common.interfaces.IRuntimeError):
"""Update Not Called
@@ -35,6 +36,16 @@
# Make it a singelton
UpdateNotCalled = UpdateNotCalled('``update()`` was not called yet.')
+class IBeforeUpdateEvent(IObjectEvent):
+
+ """A Contentprovider will be updated"""
+
+class BeforeUpdateEvent(ObjectEvent):
+
+ """A Contentprovider willt be updated"""
+
+ zope.interface.implements(IBeforeUpdateEvent)
+
class IContentProvider(browser.IBrowserView):
"""A piece of content to be shown on a page.
@@ -99,7 +110,6 @@
raise an ``UpdateNotCalled`` error.
"""
-
class IContentProviderType(zope.interface.interfaces.IInterface):
"""Type interface for content provider types (interfaces derived from
IContentProvider).
Modified: Zope3/trunk/src/zope/viewlet/README.txt
===================================================================
--- Zope3/trunk/src/zope/viewlet/README.txt 2007-04-18 05:34:45 UTC (rev 74233)
+++ Zope3/trunk/src/zope/viewlet/README.txt 2007-04-18 09:24:06 UTC (rev 74234)
@@ -121,9 +121,20 @@
... IBrowserView, ILeftColumn),
... interfaces.IViewlet, name='sport')
-and thus the left column is filled:
+and thus the left column is filled. Note that also events get fired
+before viewlets are updated. We register a simple handler to
+demonstrate this behaviour.
+ >>> from zope.contentprovider.interfaces import IBeforeUpdateEvent
+ >>> events = []
+ >>> def handler(ev):
+ ... events.append(ev)
+ >>> zope.component.provideHandler(handler, (IBeforeUpdateEvent,))
>>> leftColumn.update()
+ >>> [(ev, ev.object.__class__.__name__) for ev in events]
+ [(<zope.contentprovider.interfaces.BeforeUpdateEvent...>, 'SportBox'),
+ (<zope.contentprovider.interfaces.BeforeUpdateEvent...>, 'WeatherBox')]
+
>>> print leftColumn.render()
<div class="box">Patriots (23) : Steelers (7)</div>
<div class="box">It is sunny today!</div>
Modified: Zope3/trunk/src/zope/viewlet/manager.py
===================================================================
--- Zope3/trunk/src/zope/viewlet/manager.py 2007-04-18 05:34:45 UTC (rev 74233)
+++ Zope3/trunk/src/zope/viewlet/manager.py 2007-04-18 09:24:06 UTC (rev 74234)
@@ -20,10 +20,12 @@
import zope.component
import zope.interface
import zope.security
+import zope.event
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.viewlet import interfaces
from zope.location.interfaces import ILocation
+from zope.contentprovider.interfaces import BeforeUpdateEvent
class ViewletManagerBase(object):
"""The Viewlet Manager Base
@@ -107,8 +109,10 @@
self._updateViewlets()
def _updateViewlets(self):
- # Update all viewlets
- [viewlet.update() for viewlet in self.viewlets]
+ """Calls update on all viewlets and fires events"""
+ for viewlet in self.viewlets:
+ zope.event.notify(BeforeUpdateEvent(viewlet))
+ viewlet.update()
def render(self):
"""See zope.contentprovider.interfaces.IContentProvider"""
More information about the Zope3-Checkins
mailing list