[Zope-dev] ZPublisher Q about obj having both __bobo_traverse__ and index_html

Phillip J. Eby pje@telecommunity.com
Mon, 24 Dec 2001 09:30:50 -0500


At 10:18 PM 12/23/01 -0800, Michael Olivier wrote:
>I'm using ZPublisher + PCGI w/o the full Zope environment.  Is it possible 
>to have an object that defines a __bobo_traverse__ method and also has an 
>index_html method?  In the example below, I would want it to traverse if 
>the URL path had more elements on it, and otherwise to call 
>index_html().  Unless I comment out the __bobo_traverse__, the index_html 
>method doesn't work.  I also tried returning None in traversal if key was 
>None, but that didn't work either.  (I am running 2.0.1, so maybe I'm 
>hitting a bug that's since been fixed.)
>
>class MsgDirList:
>     """message directory list"""
>
>     def __init__(self):
>         pass
>
>     def __bobo_traverse__(self, REQUEST, key):
>         # traverse if there is more in the URL path...

Try putting this in right here:

          if key=='index_html': return self.index_html

>         return CitiesMsgs(key)

index_html is *added* onto the URL for traversal, so your __bobo_traverse__ 
should get asked for it.  Note that you return self.index_html *without* 
calling it, as ZPublisher will do that for you.