[Zope] Getting a "Handle" to a ZODB object to store in another object

Casey Duncan c.duncan@nlada.org
Thu, 29 Nov 2001 08:55:23 -0500


On Wednesday 28 November 2001 06:06 pm, John Ziniti allegedly wrote:
> Hi all,
>
> I would like to have an object in one folder be referenced
> by another object in another folder (think symlinks
> in UNIX) ... but I'm not sure what properties an object
> has that identify it's absolute location (absolute_url
> is a little fluffy, no?).
>
> Anyone have any ideas on how to approach this?
>
> Thanks in advance,
>
> Ziniti

I think Chris M. alludes to this, but it is actually trivial to "mount" an 
object in multiple places in the ZODB. However, the two objects will need to 
have the same id, due to the way Zope objects currently identify themselves.

It is theoretically possible for infinite acquisition loops to happen I think 
too, so if your Zope instance turns into a black hole and swallows the entire 
universe, don't say you haven't been warned. 8^)

Here is the code, which could be put into an external method, folder is any 
folderish object decending from ObjectManager:

from Acquisition import aq_base
def mountAgain(object, folder):
    folder._setObject(object.getId(), aq_base(object), set_owner=0)

If the objects in question are not "full Zope objects", that is they do not 
show as individual objects in the ZMI, then you can do as Chris suggests and 
just reference the object from another place.

hth,
/---------------------------------------------------\
  Casey Duncan, Sr. Web Developer
  National Legal Aid and Defender Association
  c.duncan@nlada.org
\---------------------------------------------------/