Re: [Zope] Getting a specific object in Python from an id string (Was [Zope]: Python method for getting contents of a sub-folder)
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)"> <A HREF="<dtml-var absolute_url>"> </dtml-with> <dtml-with expr="getattr(container/context/_.getitem('sequence-item'), title)"> <dtml-var title></A><BR> </dtml-with> </dtml-in> ? Could it really be that easy? Ron
If you mean the object id as used inside the ZODB to identify an object, then you (probably) will need to use an external method.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
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
participants (2)
-
complaw@hal-pc.org -
Dieter Maurer