========= Site view ========= All Azax views are not only a browser view but provide a site manager as well. The site manager is hooked into the component framework on creation time. This allows the Azax views to intercept all incomming events. By doing so the view is able to hookup it's own event redispatcher. This is a normal event handler which generates the specific Azax events. These events contain a reference to the view itself. By doing so event handlers can modify the response body. This behaviour is needed for making event driven changes to a page. For instance when you change a title in a document you also want the menu reloaded. By using events for this we can achieve a degree of decoupling. The main class which implements views with a site manager is `SiteView`. >>> from kss.core.azaxview import SiteView When created this view will make it's manager the default site manager. Context must be >>> from zope import component >>> old_sitemanager = component.getSiteManager() >>> view = SiteView(None, None) >>> old_sitemanager is component.getSiteManager() False >>> view.getSiteManager() is component.getSiteManager() True It also immediatly registers its special event handler. Like mentioned earlier this will dispatch IAzaxEvent's. >>> from zope.component.eventtesting import getEvents, clearEvents >>> from kss.core.interfaces import IAzaxEvent >>> from zope.lifecycleevent import ObjectModifiedEvent >>> from zope.event import notify >>> clearEvents() >>> notify(ObjectModifiedEvent(None)) Two events are fired by this. >>> len(getEvents()) 2 The original event and the special IAzaxEvent. >>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent >>> original_event = getEvents()[0] >>> IObjectModifiedEvent.providedBy(original_event) True >>> azax_event = getEvents()[1] >>> IAzaxEvent.providedBy(azax_event) True The Azax event has reference to the view and the original event. >>> azax_event.event is original_event True >>> azax_event.view is view True When the view is rendered it unregisters itself as a site. >>> view.render() >>> view.getSiteManager() is component.getSiteManager() False The view also has a specific way of unregistering itself for events. You can use this from your tests or other specific use cases. First we will create a new view to start listening. >>> view = SiteView(None, None) Now we will stop the view from listening to the events. >>> view.stopEventListening() If we raise an event we should only get the one event and not the AzaxEvent as well. >>> clearEvents() >>> notify(ObjectModifiedEvent(None)) >>> len(getEvents()) 1 >>> original_event = getEvents()[0] >>> IObjectModifiedEvent.providedBy(original_event) True