[Zope3-Users] how to access the root folder in normal operation
Thierry Florac
thierry.florac at onf.fr
Fri Nov 17 08:30:11 EST 2006
Le vendredi 17 novembre 2006 à 16:59 +0530, Shailesh Kumar a écrit :
> Hi,
>
> zope.traversing.api.getRoot returns the root of a given object. What
> I wanted to do was that when zope starts, I would like to create a few
> content objects inside the root folder.
>
> Something like:
> root = getRootFolder() #using some way I don't know.
> root['etc'] = Folder()
> root['var'] = Folder()
> ...
>
> Is it possible to do that?
I currently use something like this, to handle a site configuration on startup (define catalog indexes...) :
from zope.app.appsetup.interfaces import \
IDatabaseOpenedWithRootEvent
from zope.app.publication.zopepublication import ZopePublication
from zope.component import adapter
@adapter(IDatabaseOpenedWithRootEvent)
def handleDatabaseOpenedWithRootEvent(event):
db = event.database
connection = db.open()
root = connection.root()
root_folder = root.get(ZopePublication.root_name, None)
...
And in ZCML :
<subscriber
handler=".handleDatabaseOpenedWithRootEvent" />
Thierry Florac
--
Chef de projet intranet/internet
Office National des Forêts - Département Informatique
2, Avenue de Saint-Mandé
75570 PARIS Cedex 12
Mél : thierry.florac at onf.fr
Tél. : +33 01.40.19.59.64
Fax. : +33 01.40.19.59.85
More information about the Zope3-users
mailing list