I want to create a simple Zope2 product that implements a “virtual” folder where a part of the path is processed by my code. A URI of the form
/members/$id/view
e.g.
/members/isaacnewton/view
should be handled by code in the /members object, i.e. a method like members.view(id='isaacnewton').
The Zope TTW Python scripts have traverse_subpath but I have no idea how to do this in my product code.
I have looked at the IPublishTraverse interface publishTraverse() but it seems very generic.
Is there an easier way?
Still the easiest way is to use the
__before_publishing_traverse__hook on themembersobject:This method is called by the publisher before traversing further; so the publisher has already located the
membersobject, and this method is passed itself (object), and the request. On the request you’ll find the traversal stack; in your example case that’ll hold['view', 'isaacnewton']and this method moves'isaacnewton'to the request under the key'member_id'(after an optional validation).When this method returns, the publisher will use the remaining stack to continue the traverse, so it’ll now traverse to
view, which should be a browser view that expects amember_idkey in the request. It then can do it’s work: