On Tue, 2010-05-04 at 11:17 -0700, Sam Brauer wrote:
> > From: Chris McDonough <chr...@plope.com>
> > To: Sam Brauer <sampbra...@yahoo.com>
> > Cc: repoze-dev@lists.repoze.org
> > Sent: Mon, May 3, 2010 11:37:15 PM
> > Subject: Re: [Repoze-dev] Folder event subscriber not called
> > 
> > On Mon, 2010-05-03 at 23:33 -0400, Chris McDonough wrote:
> > > Hi Sam,
> > >
> > > The events sent by repoze.folder are "object events", which are events
> > > dispatched based on *two* interfaces (the context interface and the
> > > event interface).  Here's an example from KARL:
> > >
> > >  <subscriber
> > >      for="repoze.lemonade.interfaces.IContent
> > >            repoze.folder.interfaces.IObjectAddedEvent"
> > >      handler=".subscribers.index_content"/>
> > >
> > > Hopefully this helps,
> > 
> > Sorry, I should have also provided the "subscribers.index_content"
> > function so you could see its argument list:
> > 
> > def index_content(obj, event):
> >     """ Index content (an IObjectAddedEvent subscriber) """
> >     catalog = find_catalog(obj)
> >     if catalog is not None:
> >         for node in postorder(obj):
> >             if is_content(obj):
> >                 path = model_path(node)
> >                 docid = getattr(node, 'docid', None)
> >                 if docid is None:
> >                     docid = node.docid = catalog.document_map.add(path)
> >                 else:
> >                     catalog.document_map.add(path, docid)
> >                 catalog.index_doc(docid, node)
> > 
> 
> 
> Chris,
> Thanks for clarifying the "object event" style of subscribers.  I saw them in 
> some example code and tried that approach too without success.
> If I modify my example such that my Content class implements an IContent 
> interface and my subscriber_test function takes object and event arguments, 
> models.py contains:


Hi Sam,

Modify your run.py so that its app function calls "hook_zca" ala:

def app(global_config, **settings):
    """ This function returns a WSGI application.
    
    It is usually called by the PasteDeploy framework during 
    ``paster serve``.
    """
    zodb_uri = settings.get('zodb_uri')
    zcml_file = settings.get('configure_zcml', 'configure.zcml')
    if zodb_uri is None:
        raise ValueError("No 'zodb_uri' in application configuration.")

    finder = PersistentApplicationFinder(zodb_uri, appmaker)
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.hook_zca()
    config.load_zcml(zcml_file)
    config.end()
    return config.make_wsgi_app()

The repoze.folder code isn't dependent on BFG; it's actually general
enough to be used in any ZODB application.  Therefore it uses the
"global" ZCA API to send events.  When you call config.hook_zca(), this
tells BFG to replace the "normal" lookup for a Zope global registry with
a lookup which returns the ZCA registry that BFG uses.

After I added this call, I tested your code, and saw your event sent to
my console.

See http://docs.repoze.org/bfg/1.2/narr/zca.html for more info.

- C


_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to