[Zope3-Users] Traversing a Tuple Field
Johan Carlsson
johanc at easypublisher.com
Wed Oct 26 05:55:28 EDT 2005
Johan Carlsson wrote:
> Hi all,
>
> I have a schema that defines a tuple field that holds object field
> of a specific type.
> Now I want to be able to traverse each object in the tuple
> by using ./<field_name>/<index>.
>
> From the Zope3 book I've learn how to create a Traverser (by
> subclassing the ContainerTraverser) but my problem is that the first name
> encountered is the field_name, but I can't return the tuple (or)
> because it's a simple object not aware of location (that would be
> fixable I guess, I've seen a LocationProxy somewhere).
> Instead I return the context, which has the effect that the
> Traverser gets called again (with the index), but I can't figure
> out how to save the state, that the <field_name> has already been
> traverser, so I'd know that the index should be look up on the field_name.
>
> Are there anyway to know which part of the URL that has been traverse,
> or to traverse ahead in the first call to the Traverser?
>
> Any advice on this problem?
Yes (found it, after I though of revisit the Life of a Request).
The request object uses to attribute to track the traversal
(well three actually (_last_obj_traversed too), but who's counting ;-)
request._traversal_stack, that holds the names to be traversed (reversed)
request._traversed_names, that holds the names that have been (or is
being) traversed (current name is last).
That means I can just pop the last item in _traversal_stack and
push it on to _traversed_names, use it to locate my object in
the tuple and return it to the called :-)
--
Johan Carlsson Tel: + 46 8 31 24 94
Colliberty Mob: + 46 70 558 25 24
Torsgatan 72 Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM
More information about the Zope3-users
mailing list