new FAQ entry: please review before I add it
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" />
On Fri, Dec 14, 2007 at 07:29:59PM +0100, Christophe Combelles wrote:
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']
I would use ZopePublication.root_name instead of hardcoding 'Application' here. Or maybe reuse getInformationFromEvent from zope.app.appsetup.bootstrap, although it smells like an internal function.
if 'mycontainer' not in root: root['mycontainer'] = MyContainer() transaction.commit() conn.close()
Then register this subscriber in your configure.zcml: <subscriber handler="myapp.CreateMyContainer" />
Marius Gedminas -- <niemeyer> I'm wondering why we have defineChecker() defined twice with exactly the same implementation under zope.security.checker... <niemeyer> Is it some kind of high-availability system? :-) -- #zope3-dev
On Dec 14, 2007 3:48 PM, Marius Gedminas <mgedmin@b4net.lt> wrote:
Or maybe reuse getInformationFromEvent from zope.app.appsetup.bootstrap, although it smells like an internal function.
It does, but you wouldn't be the first to use it outside it's module. :-) -Fred -- Fred L. Drake, Jr. <fdrake at gmail.com> "Chaos is the score upon which reality is written." --Henry Miller
Fred Drake a écrit :
On Dec 14, 2007 3:48 PM, Marius Gedminas <mgedmin@b4net.lt> wrote:
Or maybe reuse getInformationFromEvent from zope.app.appsetup.bootstrap, although it smells like an internal function.
It does, but you wouldn't be the first to use it outside it's module. :-)
Actually, wouldn't it be nice (and logical) to transmit the root folder along with the event? It would be easier: def CreateMyContainer(event): root = event.root (...) Though it would require to add an attribute to IDatabaseOpenedWithRootEvent But that wouldn't hurt a lot...
-Fred
On Friday 14 December 2007, Christophe Combelles wrote:
Actually, wouldn't it be nice (and logical) to transmit the root folder along with the event?
+1 Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training
participants (5)
-
Benji York -
Christophe Combelles -
Fred Drake -
Marius Gedminas -
Stephan Richter