[Zope] restrictedTraverse versus unrestrictedTraverse versus
Max M
maxm at mxm.dk
Mon Sep 15 15:20:02 EDT 2003
nwingfield at che-llp.com wrote:
> Q1. What is the difference between restrictedTraverse and
> unrestrictedTraverse? When would one use the latter over the former?
> Q2. In product code, what is the value in using
> 'self.restrictedTraverse(id)' or 'self.unrestrictedTraverse(id)' versus
> simpler notation, such as 'self[id]' or 'getattr(self, id)' ?
restrictedTraverse() can take a path as an argument, while self[id] only
takes an id.
This is especially usefull if you want to make a reference to another
object. For various reasons it is better to save the full path rather
than just the id.
Ie. if you have a form with a multiple select box where you can choose
from a list of objects found by a catalog query. Then it is useless to
only save the id of the objects, as they can be positioned anywhere in
the hierachy.
<select name="objects">
<option="/path/to/obj1"Object 1</>
<option="/position/of/obj2"Object 2</>
</select>
regards Max M
More information about the Zope
mailing list