[Zope-dev] ZPatterns question
Steve Alexander
steve@cat-box.net
Thu, 28 Dec 2000 22:45:46 +0000
Steve Spicklemire wrote:
>
> CS> 2. Is it planned to provide something like a virtual folder
> CS> which acts like a normal object manager but is controlled via
> CS> ZPatterns (so actually something like Folder with Customizer
> CS> Support just without the "anchor" in ZODB. (would also
> CS> require some mechanism asked for in 1.)
>
> Hmmm... I'm not sure what you're after here. Why not just use
> a Specialist? In what sense do you want it to be virtual?
> (Are you looking for a dynamic traversal interface that
> would allow you to map URLs to objects that are managed by
> ZPatterns? Can you give an example?)
Reading this just after reading the source to Specialists.py, I had a
thought; and tried it out; and it works! :-)
You can use SkinScript to define __bobo_traverse__ for a particular kind
of DataSkin in a Specialist.
For example:
WITH SELF COMPUTE __bobo_traverse__=traversal_method
Then, define a method in the specialist (or rack) called
traversal_method. I used a PythonScript, and gave it the parameter list
"REQUEST, name".
Make your method return the appropriate object to traverse to from your
DataSkin, depending on the name passed. Something like
return getattr(container.path.to.somewhere, name)
That's the simple version, and it won't give the traversed-to object the
correct context most of the time. To do that, I'd need to use an
external method, and use the __of__ method to give the returned object
an appropriate context.
However, it is a start, and proves that it can be done.
Take a look in the __bobo_traverse__ method of Specialists.py (from
ZPatterns) for a good algorithm for traversal. The variable _marker is
almost always a class attribute initialized to [], to make a unique
object, as a sentinel.
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net