Traversing from Python a Zope 3 page that uses the traverse subpath

Getting the traverse subpath in Zope 2 is relatively easy and involves almost no tricks. Doing the same thing in Zope3 is a bit more involved, but nevertheless still relatively easy. What might not be obvious at first is how to traverse to the page from Python code. Call me slow, but it took me about 2 minutes to think of the solution.
The idea is: I have a page along these lines: http://localhost/site/tips/page_context/next. 'tips' is the page that is published, 'page_context' is a string that contains a unique page context key for which I get the tips and 'next' is an operation I want to do, based on which I get the tips content. I'm doing this because I'm storing in the session a history of 'seen tips', so that I can navigate them forward/backward.

So how does one get that page from python code? Like this:

page_context = 'my_page'
tips_page = getMultiAdapter((self.context, self.request), name='tips')
tip_content = tips_page.publishTraverse(self.request, page_context).publishTraverse(self.request, 'next')()


Comments