[Zope] Help needed with __bobo_traverse__

Evan Simpson evan@zope.com
Wed, 20 Feb 2002 09:59:39 -0500


jkinsley wrote:
> 	1. I can extract refid (the virtual sub-object)
> 
> 	2. Do a database lookup with refid
> 
> 	3. Set session data based on lookup results
> 
> 	4. Return a response as if http://localhost/rest/of/path/ 
> 	   were called without the refid segment in the path

This is best accomplished with the __before_publishing_traverse__ hook, 
since that allows you to examine and manipulate passing requests without 
handling them yourself.

See 
http://www.zope.org/Members/michel/Projects/Interfaces/BeforePublishingTraverse.

Since you control the class of "myObject", you don't need to use the 
hook management interface.  You can just write something like:

def __before_publishing_traverse__(self, object, request):
     stack = request['TraversalRequestNameStack']
     if stack[-1][:7] == 'manage_':
         # Crude hack!  You may want to check the name
         # against class attributes instead.
         return
     refid = stack.pop()
     # do lookup
     request.set('foo', bar)

Cheers,

Evan @ Zope