thanks Chris!


Chris Withers wrote:
Hi All,

Just been playing with this and found it remarkably easy, so thought I'd pass it on. If anyone can think of a better place than the mailing list archives for this, please let me know!

Anyway, so I'm building a Zope 2 app where I need to index objects that are not catalog aware when they're added, modified or removed. To make things harder, this also needs to work via WebDAV.

OK, so here's the solution:

1. Create yourself a python module called and put it on your python path, containing the following:

from Acquisition import aq_base
from zope.interface import Interface

class ICatalogAware(Interface): pass

def catalog(object,event):
    if aq_base(object) is object:
        # ObjectModified can get emitted during creation,
        # before the object has any acquisition context

def uncatalog(object,event):

2. Slap the ICatalogAware marker interface on any classes you want to have indexed. Here's an example for the good old File object. Put the following in your site.zcml:

<class class="OFS.Image.File">
<implements interface="subscribers.ICatalogAware"/>

3. Finally, wire up the events so that files get indexed when they're created, modified or removed, again by adding the following to site.zcml:




4. Okay, sadly you do need to get do some patching if you want changes to the file to result in recataloging :-/ Here's a diff:

---   2006-09-26 16:32:20.759375000 +0100
+++    2006-09-26 16:33:11.384375000 +0100
@@ -33,6 +33,8 @@
 from ZPublisher.HTTPRequest import FileUpload
 from ZPublisher.Iterators import filestream_iterator
 from zExceptions import Redirect
+from zope.event import notify
+from import ObjectModifiedEvent
 from cgi import escape
 import transaction

@@ -437,6 +439,7 @@
+        notify(ObjectModifiedEvent(self))

     def manage_edit(self, title, content_type, precondition='',
                     filedata=None, REQUEST=None):

Okay, well, hope this helps someone :-)


Zope maillist  -
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to