[Zope3-checkins]
SVN: Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.
Make getViews() support lookup up view registrations from
local component
Philipp von Weitershausen
philikon at philikon.de
Thu Mar 2 17:28:00 EST 2006
Log message for revision 65753:
Make getViews() support lookup up view registrations from local component
registrations.
Changed:
U Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.py
U Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.txt
-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.py 2006-03-02 22:03:00 UTC (rev 65752)
+++ Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.py 2006-03-02 22:27:59 UTC (rev 65753)
@@ -118,10 +118,10 @@
return iface
-def getViews(iface, type=IRequest):
+def getViews(iface, type=IRequest, context=None):
"""Get all view registrations for a particular interface."""
- gsm = zapi.getGlobalSiteManager()
- for reg in gsm.registrations():
+ sm = zapi.getSiteManager(context)
+ for reg in sm.registrations():
if (isinstance(reg, AdapterRegistration) and
len(reg.required) > 0 and
reg.required[-1] is not None and
Modified: Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.txt 2006-03-02 22:03:00 UTC (rev 65752)
+++ Zope3/branches/jim-adapter/src/zope/app/apidoc/presentation.txt 2006-03-02 22:27:59 UTC (rev 65753)
@@ -240,8 +240,8 @@
presentation type to be an `IBrowserRequest`.
-`getViews(iface, type=IRequest)`
---------------------------------
+`getViews(iface, type=IRequest, context=None)`
+----------------------------------------------
This function retrieves all available view registrations for a given interface
and presentation type. The default argument for the presentation type is
@@ -279,10 +279,43 @@
[AdapterRegistration(('Interface', 'IHTTPRequest'), 'Interface',
'bar', None, '')]
+We can also pass a ``context`` parameter to get registration objects
+from a local site manager. First we create a fake context object:
-`filterViewRegistrations(regs, iface, level=SPECIFC_INTERFACE_LEVEL)`
----------------------------------------------------------------------
+ >>> class MyContext(object):
+ ... pass
+ >>> context = MyContext()
+Now we create a local component registration (a.k.a. site manager) and
+register an adapter that finds it:
+
+ >>> import zope.interface
+ >>> import zope.component.globalregistry
+ >>> import zope.component.interfaces
+ >>> sm = zope.component.globalregistry.BaseGlobalComponents()
+
+ >>> @zope.component.adapter(MyContext)
+ ... @zope.interface.implementer(zope.component.interfaces.IComponentLookup)
+ ... def contextToComponentLookup(context):
+ ... return sm
+ >>> zope.component.provideAdapter(contextToComponentLookup)
+
+Now we register a local view and see that ``getViews()`` with the
+appropriate context gives us an according AdapterRegistration:
+
+ >>> class LocalView(object):
+ ... pass
+ >>> sm.registerAdapter(LocalView, (Interface, IBrowserRequest),
+ ... Interface, name=u'localview.html')
+
+ >>> list(presentation.getViews(Interface, IBrowserRequest, context))
+ [AdapterRegistration(('Interface', 'IBrowserRequest'), 'Interface',
+ u'localview.html', 'LocalView', u'')]
+
+
+`filterViewRegistrations(regs, iface, level=SPECIFIC_INTERFACE_LEVEL)`
+----------------------------------------------------------------------
+
Oftentimes the amount of views that are being returned for a particular
interface are too much to show at once. It is then good to split the view into
categories. The `filterViewRegistrations()` function allows you to filter the
More information about the Zope3-Checkins
mailing list