Skip to content

Commit

Permalink
Revert r65753. It broke other tests and I don't think I'm gonna need …
Browse files Browse the repository at this point in the history
…this anyways.
  • Loading branch information
philikon committed Mar 3, 2006
1 parent e3f6f7c commit ae3a578
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
6 changes: 3 additions & 3 deletions presentation.py
Expand Up @@ -118,10 +118,10 @@ def getPresentationType(iface):
return iface


def getViews(iface, type=IRequest, context=None):
def getViews(iface, type=IRequest):
"""Get all view registrations for a particular interface."""
sm = zapi.getSiteManager(context)
for reg in sm.registrations():
gsm = zapi.getGlobalSiteManager()
for reg in gsm.registrations():
if (isinstance(reg, AdapterRegistration) and
len(reg.required) > 0 and
reg.required[-1] is not None and
Expand Down
41 changes: 4 additions & 37 deletions presentation.txt
Expand Up @@ -240,8 +240,8 @@ Note that more specific presentation types are considered first. For example,
presentation type to be an `IBrowserRequest`.


`getViews(iface, type=IRequest, context=None)`
----------------------------------------------
`getViews(iface, type=IRequest)`
--------------------------------

This function retrieves all available view registrations for a given interface
and presentation type. The default argument for the presentation type is
Expand Down Expand Up @@ -279,42 +279,9 @@ should be returned:
[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:

>>> 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)`
----------------------------------------------------------------------
`filterViewRegistrations(regs, iface, level=SPECIFC_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
Expand Down

0 comments on commit ae3a578

Please sign in to comment.