[BlueBream] Loading initial data into DB from paster

Marc Rijken marc at rijken.org
Tue May 24 09:41:59 EDT 2011


Hi Joe,

> What is the preferred way to load initial data into the db?
> 

I have solved this by listening to IDatabaseOpenedEvent and then fill the 
database when certain data is not present. I use the following code for my 
grok applications:

@grok.subscribe(zope.app.appsetup.interfaces.IDatabaseOpenedEvent)
def checkInstalledApplications(event):
    conn = event.database.open()
    root = conn.root()
    approot = root['Application']

    if not app_name in approot:
            #fake request, because request will be used for caching
            request = zope.publisher.browser.TestRequest()
            zope.security.management.newInteraction(request)

            approot[app_name] = Application()

            transaction.commit()

            #end fake request
            zope.security.management.endInteraction()

Is this you're looking for?

Regards,

Marc





More information about the bluebream mailing list