[Zope-dev] Specialists and __bobo_traverse__
Steve Alexander
steve@cat-box.net
Mon, 15 Jan 2001 13:11:29 +0000
Roch'e Compaan wrote:
> Recent sightings of the use of __bobo_traverse__ in SkinScript gave me hope
> of giving users a more useable breadcrumbs trail in the case where I have
> nested specialists.
>
> My TaskTemplates specialist is nested inside my RequestTypes specialist.
> When I retrieve a dataskin from the RequestTypes specialist I have a tab
> that lists TaskTemplates for that RequestType specialist. Following a link
> from the TaskTemplate list takes you to that instance.
>
> Thus results in a url like this:
> /RequestTypes/<request type instance>/Task Templates/<task template
> instance>,
> and what I ideally want is:
> /RequestTypes/<request type instance>/<task template instance>.
>
> I read all the comments about __bobo_traverse__ and created a python method,
> "traversal_method" inside the "RequestTypes" specialists. I must admit that
> I don't really understand Zope's traversal machinery yet and would
> appreciate some guidance.
With your code below, and with a concrete example, can you say what you
want to happen, and what actually does happen?
> My SkinScript for RequestTypes:
>
> WITH SELF COMPUTE __bobo_traverse_=traversal_method
You'll want another underscore in there: __bobo_traverse__
> My traversal_method:
>
> ob = getattr(self, name)
> if ob is not None:
> return ob
If ob is not found, you'll get an error raised. You need to have some
sort of marker for the default value.
marker=[]
ob=getattr(self, name, marker)
if ob is not marker:
return ob
# continue your method
Of course, you only need one marker in your class. You can do that if
you implement your method as an external method, or perhaps with a
default value for an argument on you python method.
Or, you could not worry about creating a new empty list on each request.
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net