[Zope] Getting a specific object in Python from an id string (Was [Zope]: Python method for getting contents of a sub-folder)

Dieter Maurer dieter@handshake.de
Thu, 23 Aug 2001 19:36:12 +0200 (CEST)


complaw@hal-pc.org writes:
 > > complaw@hal-pc.org writes:
 > >  > ....
 > > If you mean with an "oid" an "id" as used by Zope as part
 > > of the URLs, then the answer is easy:
 > > 
 > >    getattr(container/context,id)
 > 
 > Okay, lets take an example where a lines property contains a list of id's (not
 > the objects themselves, simply a string representation of the id's).  Then to
 > get the url and title properties of a given id in the lines property, could I
 > simply...
 > 
 > <dtml-in my_lines_property>
 >   <dtml-with expr="getattr(container/context/_.getitem('sequence-item'),
 > absolute_url)">
Didn't you speak of a Python Script originally?

The "getattr" is for the Python Script.

In DTML you have either:

	<dtml-with expr="_.getitem(_['sequence-item'])">

if your object is already on the DTML namespace
or

	<dtml-with expr="_.getattr(obj,_['sequence-item'])"

if you are interested in the attributes of "obj".


Dieter