[Zope] String to object ID

Chris McDonough chrism@digicool.com
Wed, 8 Dec 1999 08:32:07 -0500


Now this is cool.

Chris McDonough     mailto:chrism@digicool.com
Digital Creations   http://www.digicool.com
Publishers of Zope  http://www.zope.org

> -----Original Message-----
> From: Evan Simpson [mailto:evan@tokenexchange.com]
> Sent: Monday, December 06, 1999 10:45 AM
> To: zope@zope.org; Goodrichs
> Subject: Re: [Zope] String to object ID
> 
> 
> 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')">
> 
> ----- Original Message -----
> From: Goodrichs <nbd95@macconnect.com>
> > Well I still don't know how to reference a Zope object from 
> a string, but
> I
> > have a interim solution for now.
> 
> 
> 
> _______________________________________________
> 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 )
>