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

Casey Duncan casey at zope.com
Thu Apr 1 16:23:02 EST 2004


On Thu, 01 Apr 2004 14:52:45 -0500
Jim Fulton <jim at zope.com> wrote:

> Tres Seaver wrote:
> > Jim Fulton wrote:
[..]
> > 
> > -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 ...

I agree, I think it's unintuitive that the request gets thrown in there
*and* it must be last.
 
>  > 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):

This seems reasonable, although Tres' interface makes it a tad bit
clearer that objects is a sequence and may be empty. The latter is the
key distinction there. I think this is ugly::
 
  getPresenter((), request, interface)

compared to::

  getPresenter(request, interface)

Granted I don't know how common the latter will be in practice.
 
> because:
> 
> - We rarely have no objects

Apparently not very.

> - We adapt the objects first -- that is, objects have more impact
>    on adapter selection than does the request

Ok, but it does seem to muddy up the case where there aren't any
objects. Since objects is optional, it seems best that it be an optional
argument regardless of how that affects the order. Otherwise that is not
immediately clear.

> - 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)

I sense that connection may not be as valuable to more casual users. If
the common case is a single object, I propose two methods::

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

and 

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

Names notwithstanding.

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

Why can't there just be presentation adapters that know about skinning
instead of a different-but-similar concept/API?

-Casey




More information about the Zope3-dev mailing list