Casey Duncan <cduncan@kaivo.com> said:
If you create a ZClass with a base class of CatalogAware, it will automatically catalog and uncatalog itself when objects of the class are created and deleted. You also get several method on the object to index, reindex, unindex, etc.
I did this today, but it doesn't seem to uncatalog itself on deletion - I put debugging code in the ZCatalog CatalogAware class and the deletion methods weren't called. Furthermore, the catalog name is hardcoded and by the time you get to your constructor method, the add-to-catalog code bit seems to have been executed (or, again, it is not called) - I needed to call the indexing method manually in my ZClass. (Zope 2.3.1) BTW, it's a really neat ZClass: it is called "Virtual Host Folder" and adds itself to a "sites" catalog - it's just CatalogAware and Folder, and contains a single object - a SiteRoot. My AccessRule on the Zope root is a bit custom, it first looks in the catalog for a host folder with a name matching the sitename, and then goes on to do other things based on a database table (like showing redirects, or our business card sites, etcetera). Some maybe useful snippets: -- ZClass constructor set custom catalog: ... <dtml-call "manage_editCataloger(default='sites')"> <dtml-call index_object> ... -- Virtual hosting bit based no catalog (external method in my case, it -- does some more things): def vhost(self, REQUEST): hostname = string.split(REQUEST['HTTP_HOST'], ':')[0] r = self.sites({ 'id': string.replace(hostname, '.', '_')}) if len(r) == 1: path = string.split(r[0].getPath(), '/')[1:] path.reverse() REQUEST['TraversalRequestNameStack'].extend(path) REQUEST.set('SiteRootPATH', '/') else: ... # the other bits :-) --