On 3/6/06, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> my content object depends on a number of utilities to be present. It is
> usually also used as a site. During development it happens often that I
> delete and recreate it.
> Can I install a hook or something so I can make that these utilies are being
> created when my objects becomes a site? How do I create utitlies in software
> space?

Check for when your root object gets added. I'm not sure if an event
is fired off when something 'becomes a site'. My pattern is to have an
Interface and Content Class for the site, and have the following in

from zope.app import zapi
from zope.interface import implements
from zope.app.component.interfaces import ISite
from zope.app.component.interfaces.registration import (
    ActiveStatus, InactiveStatus, IRegistered)
from zope.app.component.site import (LocalSiteManager, UtilityRegistration,
from zope.app.container.interfaces import IObjectAddedEvent
from zope.app.intid import IntIds
from zope.app.intid.interfaces import IIntIds

def setupSiteManagerSubscriber(event):
    event is supposed to be an IObjectAddedEvent

    An event subscriber which calls setupSiteManager when a Site folder is
    added. This ensures that there's enough placeful context in place for the
    site configuration and utility registration to happen whenever a Site
    is added and an IObjectAddedEvent is fired off.
    assert IObjectAddedEvent.providedBy(event)

    if IMyApplicationSite.providedBy(event.object):

def setupSiteManager(context):
    Configures the application manager's local utilities.
    if not ISite.providedBy(context):
    # Required for getUtility to work within this request

    # Get the default registration
    default = context.getSiteManager()['default']
    reg_manager = default.registrationManager

    if 'intid' not in default:
        # There's a shorter way to do this, but I can never remember what it is
        intid = IntIds()
        default['intid'] = intid
        intids_reg = UtilityRegistration('', IIntIds, intid)
        intids_reg.status = ActiveStatus

    # Set up the 'auth' utility
    if 'auth' not in default:
        # This is a custom function that wraps up all of the work involved
        # setting up the pluggable auth utility and its sources.
        from myapp.security.browser import establish
            default, realm='Killer App', registerAs=''

    # etc...

And then in configure.zcml:
  <subscriber for="zope.app.container.interfaces.IObjectAddedEvent"

Jeff Shell
Zope3-users mailing list

Reply via email to