Help needed with __bobo_traverse__
Greetings, I have a Product, myObject, that is acting as a Site Root (containing a Site Root object). So now http://localhost/myObject/rest/of/path/ is accessable as http://localhost/rest/of/path/ Now then I want to add an optional 'virtual sub-object' in the path so that when http://localhost/refid/rest/of/path/ is called the following will happen. 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 I have created a __bobo_traverse__ method in myObject and accomplished the first three steps, but I have no idea what to return to complete step four. Any help will be greatly appreciated since I have spent the last eight hours trying to figure this out. Regards, Jarrod Kinsley
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/BeforePublishingTrave.... 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
jkinsley writes:
I have a Product, myObject, that is acting as a Site Root (containing a Site Root object).
So now http://localhost/myObject/rest/of/path/ is accessable as http://localhost/rest/of/path/
Now then I want to add an optional 'virtual sub-object' in the path so that when http://localhost/refid/rest/of/path/ is called the following will happen.
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
I have created a __bobo_traverse__ method in myObject and accomplished the first three steps, but I have no idea what to return to complete step four. I think you have already be told about the "__before_publishing_traverse__" hook.
I would probably use a SiteAccess AccessRule. It internally uses the above hook. Dieter
participants (3)
-
Dieter Maurer -
Evan Simpson -
jkinsley