[Zope-dev] Accessing root object

Martijn Pieters mj@digicool.com
Sat, 12 Feb 2000 19:49:50 -0500


> From: Robert Sander [mailto:zope-dev@beteigeuze.cs.tu-berlin.de]
> 
> On Thu, Feb 10, 2000 at 03:40:38PM -0000, Phil Harris wrote:
> > I think there's something  called app?
> > 
> > It's declared in <zopedir>/lib/python/Main.py.
> > 
> > That may be what your looking for??
> 
> I don't know, the object app is not in the global namespace 
> when __init__.py 
> of my Product is called.
> 
> It may be the same problem with the discussed scheduler 
> product when creating 
> another thread, b ut I don't know.

Here's what I'd do (in __init__.py):

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

context._ProductContext__app is the root object. #IdForObject# is a
string ID for the object.

-- 
Martijn Pieters, Software Engineer 
| Digital Creations http://www.digicool.com 
| Creators of Zope      http://www.zope.org 
| mailto:mj@digicool.com       ICQ: 4532236
| PGP:
http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 
-------------------------------------------