[Product-Developers] Re: Making an adapter traversable

Martin Aspeli optilude at gmx.net
Tue Jul 15 21:59:27 UTC 2008

Hedley Roos wrote:
> Hi all
> I'm playing around with schemaextender and it is very useful. I'm
> trying to make a method on my adapter traversable, so if I navigate to
> http://server/my-adapted-object/foo I want method foo to execute.

This isn't really possible without subclassing, though you could 
register view 'foo' for the type, and then have that call the method and 
do something.

In general, the idea of traversing to methods is a bit fishy. If you 
want something to be traversable, you should think views.

> I've got this method on the adapter
> def foo(self):
>   """Callable"""
>   return "something"
> My configure.zcml has
> 'provides="zope.traversing.interfaces.ITraversable"' in the adapter
> registration. My class does implements(ISchemaExtender, ITraversable),
> but it subclass only object and not Traversable.

This doesn't work. It's the context object that needs to be traversable 
(which it is anyway, just not in the way you want it to be).

> I keep getting an Unauthorized error. Setting
> __allow_access_to_unprotected_subobjects also does nothing.

Who knows why, but 'foo' is not an attribute on your object even though 
the schema extender adds it to its Schema().

> What is the correct combination to get it working?

Views. ;-)


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

More information about the Product-Developers mailing list