Back to index

plone3  3.1.7
events.py
Go to the documentation of this file.
00001 import zope.component
00002 
00003 from zope.interface import Interface
00004 from zope.component.interfaces import IUtilityRegistration
00005 from zope.component.interfaces import IRegistrationEvent
00006 from zope.component.interfaces import IRegistered
00007 from zope.component.interfaces import IUnregistered
00008 
00009 from zope.publisher.interfaces.browser import IBrowserRequest
00010 from zope.publisher.interfaces.browser import IBrowserView
00011 
00012 from plone.portlets.interfaces import IPortletManager
00013 from plone.portlets.interfaces import IPortletManagerRenderer
00014 
00015 @zope.component.adapter(IUtilityRegistration, IRegistrationEvent)
00016 def dispatchToComponent(registration, event):
00017     """When a utility is registered, dispatch to an event handler registered for 
00018     the particular component registered, the registration and the event.
00019     """
00020     handlers = zope.component.subscribers((registration.component, registration, event), None)
00021     for handler in handlers:
00022         pass # getting them does the work
00023       
00024 @zope.component.adapter(IPortletManager, IUtilityRegistration, IRegistered)
00025 def registerPortletManagerRenderer(manager, registration, event):
00026     """When a portlet manager is registered as a utility, make an appropriate
00027     adapter registration for its IPortletManagerRenderer so that the
00028     provider: expression can find it, and ensure the manager's __name__ is 
00029     the same as the name of the utility, which will also be the name of the
00030     adapter.
00031     """
00032     manager.__name__ = registration.name
00033     registry = registration.registry
00034     registry.registerAdapter(factory=manager,
00035                              required=(Interface, IBrowserRequest, IBrowserView),
00036                              provided=IPortletManagerRenderer,
00037                              name=registration.name)
00038                              
00039 @zope.component.adapter(IPortletManager, IUtilityRegistration, IUnregistered)
00040 def unregisterPortletManagerRenderer(manager, registration, event):
00041     """When a portlet manager is unregistered as a utility, unregister its 
00042     IPortletManagerRenderer.
00043     """
00044     registry = registration.registry
00045     registry.unregisterAdapter(factory=manager,
00046                                required=(Interface, IBrowserRequest, IBrowserView),
00047                                provided=IPortletManagerRenderer,
00048                                name=registration.name)