[Zope-dev] new FAQ entry: please review before I add it

Christophe Combelles ccomb at free.fr
Fri Dec 14 13:29:59 EST 2007


how do I automatically create some needed object at application startup?

Do it by subscribing to IDatabaseOpenedWithRootEvent (from zope.app.appsetup)

Example code:

@adapter(IDatabaseOpenedWithRootEvent)
def CreateMyContainer(event):
     conn = event.database.open()
     root = conn.root()['Application']
     if 'mycontainer' not in root:
         root['mycontainer'] = MyContainer()
     transaction.commit()
     conn.close()

Then register this subscriber in your configure.zcml:
<subscriber handler="myapp.CreateMyContainer" />


More information about the Zope-Dev mailing list