On Thu, 2012-03-01 at 22:36 +0700, Jonathan Ballet wrote:
> On Thu, Mar 01, 2012 at 10:29:29AM -0500, Chris McDonough wrote:
> > On Thu, 2012-03-01 at 20:26 +0700, Jonathan Ballet wrote:
> > > Hello,
> > > 
> > > I have some code which looks like this:
> > > 
> > >     @adapter(IFolder)
> > >     @implementer(IImage)
> > >     def thumbnail_of_folder(folder):
> > >         return IImage(folder[0])
> > > 
> > > I want this to adapt and recurse into the subfolders until it founds an
> > > IImage (the example assumes there's always something into the folder).
> > > 
> > > If I want to use the registry associated to the request being processed,
> > > I can do something like:
> > > 
> > >     request.registry.queryAdapterOrSelf(context, IImage)
> > > 
> > > If `context` is not an IImage, it goes into the adapter defined above
> > > where I'm stuck, since I don't have access to the request's registry
> > > anymore.
> > > 
> > > Is there a way to call nested (recursive, here) adapters using Pyramid's
> > > registry, or am I doing something wrong here?
> > 
> > If you really want a global registry, you can do:
> 
> Yes, I read the document you mentioned, but I actually want to know if
> there is a way and how to do *without* using the global registry or
> accessing the thread-local registry.

No, there's no declarative way to spell "ascend my content tree trying
to find an adapter".  There's the inverse in the "containment="
predicate to a view or the pyramid.traversal.find_iterface adapter,
where it tries to look towards the root for some object which implements
some interface.  But it doesn't have anything to do with adaptation.

> FWIW, I like the idea described in the aforementioned document, although
> it somehow looks it's not meant to be used this way.

"Meant to be used" is a pretty slippery measure.  But personally if I
were you I'd just write a function that took the context and the request
and which walked up the tree looking for something that was adaptable to
IImage.  Trying to solve this with adaptation is maybe not useful,
especially if you have to create a global to do it.

- C


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to