[Zope3-Users] Re: zopeproject auto create instance

Philipp von Weitershausen philipp at weitershausen.de
Fri Sep 28 14:02:42 EDT 2007


Michael Ang wrote:
> Hi, I am new to zope3 and zopeproject.
> I have a question, how do I create an instance of my (IContainer) class
> when initial startup of a zopeproject?
> 
> For Plone, I can inject in Extensions/Install.py.
> 
> Hope you understand my question, thanks.

Write an IDatabaseOpenedWithRootEvent handler:


import zope.component
from zope.app.appsetup.interfaces import IDatabaseOpenedWithRootEvent
from zope.app.appsetup.bootstrap import getInformationFromEvent

   @zope.componen.adapter(IDatabaseOpenedWithRootEvent)
   def createInitialFolder(event):
       db, connection, root, root_folder = getInformationFromEvent(event)
       if 'myfolder' not in root_folder:
           root_folder['myfolder'] = MyContainer()


and register it as a subscriber:

   <subscriber handler="...createInitialFolder" />

-- 
http://worldcookery.com -- Professional Zope documentation and training



More information about the Zope3-users mailing list