[Zope-dev] Accessing root object

Evan Simpson evan@4-am.com
Fri, 18 Feb 2000 00:55:49 -0600


----- Original Message -----
From: Loren Stafford <lstaffor@dynalogic.com>
> I can't figure out the opposite angle on this. In __init__.py, my product
> creates a root-level object named 'S' with Martijn's method below. Now
> another module 'D'  needs to look up 'S' and get a reference to the object
> so it can call one of its methods "S.next". But I don't see how to look up
> 'S'. I'm sure I'm just being dense. Can somebody help?

Sure! There are a few ways to do it, but one is to add a pair of lines
here...

> >   def initialize(context):
> >       app = context._ProductContext__app # Don't you love private name
> > mangling
       global object
       object = getattr(app, #IdForObject#, None)
       if object is None:
> >           object = Object()
> >           app._setObject(#IdForObject#, object)
> >           get_transaction().note('Added Object')
> >           get_transaction().commit()

...and in your other Product(s) do...

from Products.#NameOfFirstProduct# import object
object.next()

Cheers,

Evan @ 4-am & digicool