[Zope] Accessing the Application (or Control_Panel)

Jeff K. Hoffman jeff.hoffman@goingv.com
Fri, 14 Jul 2000 15:30:36 -0400 (EDT)


Hello,

I am working on a Python Product (subclass of ObjectManager) that creates
some instances of a few ZClasses inside itself when constructed.
Currently, I do this as follows:

  CONTROL_PANEL = None

  def manage_addMyClass(self, id, title='', REQUEST=None):
      global CONTROL_PANEL
      if CONTROL_PANEL is None:
          CONTROL_PANEL = self.Control_Panel

      self._setObject(id, MyClass(id, title))

      ...

  class MyClass(...):
      def __init__(self, id, title=''):
          self.id = id
          self.title = title

          ob = CONTROL_PANEL.Products.MyProduct.MyClass('myId')
          ob.id = 'myId'
          self._setObject('myId', ob)

which works fine, until I need to use CONTROL_PANEL from somewhere else
before manage_addMyClass is called (currently, I am trying to upgrade
existing instances in __setstate__). Inside __setstate__,
self.Control_Panel throws an exception, for understandable reasons.

So, I get the feeling I am going about this incorrectly. I grep'd the
source last night, looking for a getApplicationInstance() method, or
something similar, but found nothing. AFAICT, there is no easy way to get
ahold of the one true Application object without having a reference to an
object in the ZODB and calling getPhysicalRoot().

Did I miss something? Is there a better way to do what I am trying to do?

--Jeff

---
Jeff K. Hoffman                               704.849.0731 x108
Chief Technology Officer                      mailto:jeff.hoffman@goingv.com
Going Virtual, L.L.C.                         http://www.goingv.com/