[Zope] String to object ID

Art Hampton arth@pacsg.css.mot.com
Tue, 07 Dec 1999 10:24:15 -0600


Thank you!!!

I've been trying to figure out how to fetch a non-meta-data property
from catalog search results.  Thanks to your script, I can do so after
doing catalog.getpath(data_record_id_).

If there's a cleaner way to do this, I'm open to suggestions.  But at
least I'm up and running!

Thanks again.


Evan Simpson wrote:
> 
> I missed some of the prior discussion, so I hope this isn't irrelevent.
> 
> Are you trying to access an object given a string such as 'hie/dee/hoe'?  If
> so, try this:
> 
> DTML Method FetchObj:
> <dtml-let obj="[_]">
>   <dtml-in expr="_.string.split(fetchStr, '/')">
>     <dtml-call expr="obj.append(obj.pop()[_['sequence-item']])">
>   </dtml-in>
>   <dtml-return expr="obj[0]">
> </dtml-let>
> 
> example call:  <dtml-var expr="_.render(FetchObj(_.None, _,
> fetchStr='hie/dee/hoe').id)">
> 
> Some notes about the above:
> o We start with a list containing the global namespace object.
> o For each path element, we pop the current object, find the sub-object, and
> put it back in the list.
> o You could use REQUEST.set instead of the list foolery if you wanted to.
> o _.render is necessary since the .id of folders is a string, while that of
> methods is a method :-P
> 
> If you use PythonMethods, the above can be more simply written as:
> 
> PythonMethod FetchObj:
> <params>_, fetchStr, attr=None</params>
> obj = _
> for p in string.split(fetchStr, '/'):
>   obj = obj[p]
> if attr is None:
>   return obj
> else:
>   return render(_.getattr(obj, attr))
> 
> <dtml-var expr="FetchObj(_, 'hie/dee/hoe', 'id')">