[Zope3-dev] Re: Mini proposal: simpify presentation-lookup api

Jim Fulton jim at zope.com
Thu Apr 1 14:52:45 EST 2004


Tres Seaver wrote:
> Jim Fulton wrote:
> 
>> I propose to replace these with:
>>
>>     def queryPresenter(objectsandrequest, interface, name='',
>>                        default=None, context=None):
>>         """Query a presentation for the objects and request
>>
>>         A components is returned that provides the given interface for
>>         the given objects and request. The objects and request are
>>         provides as a tuple. The request must be the last item in the
>>         tuple.  Zero or more non-request objects may be provided.
>>         A name may be provided to quality the presentation.
>>
>>         If a presentation can't be found, the default is returned.
>>
>>         A context may be provided to control where components are 
>> looked up.
>>         """
>>
>>     def getPresenter(objectsandrequest, interface, name='',
>>                      context=None):
>>         """Get a presentation for the objects and request
>>
>>         A components is returned that provides the given interface for
>>         the given objects and request. The objects and request are
>>         provides as a tuple. The request must be the last item in the
>>         tuple.  Zero or more non-request objects may be provided.
>>         A name may be provided to quality the presentation.
>>
>>         If a presentation can't be found, a ComponentLookupError is 
>> raised.
>>
>>         A context may be provided to control where components are 
>> looked up.
>>         """
> 
> 
> -1 to 'objectsandrequest';  if the request is special, and required, and
> must be in a specific position, then it should not be "lumped" with the 
> objects. 

That's a reasonable argument ...

 > Why not:
> 
>     def getPresenter(request, interface, objects=(), name='',
>                      context=None):
>         """..."""
> 
> Because presenters are *always* adapting requests to an interface, but 
> *may* take into account other objects, and *may* have a name, this seems 
> cleaner.  We could move the interface to be first, if that makes it 
> clearer.

I prefer either what I proposed or:

     def getPresenter(objects, request, interface, name='',
                      context=None):

because:

- We rarely have no objects
- We adapt the objects first -- that is, objects have more impact
   on adapter selection than does the request
- I want to make this look like an adapter lookup:

     def getMultiAdapter(objects, interface, name='', context=None)

It's most common to have 1 object, other than the request.  Lumping
the object with the request avoids:

     view = getPresenter((x, ), request, someinterface):

I like:

     view = getPresentation((x, request), someinterface)

because it's alot like:

     adapter = getMultiAdapter((x, y), someinterface)

Note that we can't use regular adapters here because presentors are
"skinned", meaning we take skinning into account when we look them up.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org




More information about the Zope3-dev mailing list