> 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: --------------------------------------------------- import repoze.folder import persistent import zope.interface class IContent(zope.interface.Interface): pass class Content(persistent.Persistent): zope.interface.implements(IContent) class Site(repoze.folder.Folder): pass def appmaker(zodb_root): if not 'app_root' in zodb_root: app_root = Site() zodb_root['app_root'] = app_root import transaction transaction.commit() return zodb_root['app_root'] def subscriber_test(obj, event): print "subscriber_test object=%s event=%s" % (repr(obj), repr(event)) --------------------------------------------------- And configure.zcml contains: --------------------------------------------------- <configure xmlns="http://namespaces.repoze.org/bfg"> <include package="repoze.bfg.includes" /> <subscriber for=".models.IContent repoze.folder.interfaces.IObjectAddedEvent" handler=".models.subscriber_test" /> </configure> --------------------------------------------------- Then I run bfgshell and add a Content object to the app root like so: $ ../bin/paster --plugin=repoze.bfg bfgshell foo.ini zodb Python 2.5.4 (r254:67916, Jan 20 2010, 21:45:54) [GCC 4.3.3] on linux2 Type "help" for more information. "root" is the BFG app root object. >>> import foo.models >>> root['test'] = foo.models.Content() >>> Nothing is printed to stdout, so it appears that again subscriber_test() isn't being called. I'm stumped. Maybe I'm missing some required code or configuration somewhere... I've been going in circles trying to figure it out. Thanks for your time, Sam _______________________________________________ Repoze-dev mailing list Repoze-dev@lists.repoze.org http://lists.repoze.org/listinfo/repoze-dev