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" />
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )

Reply via email to