[Zope-dev] Catalog Awareness

Robert Leftwich robert@leftfieldcorp.com
Wed, 17 Nov 1999 10:46:33 +1100


Is anyone using the CatalogAware mixin from CatalogAwareness.py ?

I am just in the process of adding catalog awareness to my project and have
found a couple of problems with it. (Note that this file has not changed
since the 14th of September as of the 2.1.0 beta 2 release.)

Firstly, you need to import aq_base from somewhere if (as in my case) you
are using python classes that are not ZClasses.

	from OFS.PropertySheets import aq_base

Secondly the reindex_all function has a problem. Here is the original
function :

    def reindex_all(self, obj=None):
        """ """
        if obj is None: obj=self
        if hasattr(aq_base(obj), 'index_object'):
            obj.index_object()
        if hasattr(aq_base(obj), 'objectValues'):
            sub=obj.objectValues()
            for item in obj.objectValues():
                reindex_all(self, item)
        return 'done!'

Note the call to reindex_all( self, item ), which fails in my environment.
Here is my replacement (which also uses the sub variable which was
initialised but not used in the original) :

    def reindex_all(self, obj=None):
        """ """
        if obj is None: obj=self
        if hasattr(aq_base(obj), 'index_object'):
            obj.index_object()
        if hasattr(aq_base(obj), 'objectValues'):
            sub=obj.objectValues()
            for item in sub:
                self.reindex_all(item)
        return 'done!'

Should this function be renamed to index_all, as it only indexes the object,
not reindexes it ?

I will post this to the collector if there are no other changes or
objections.

Robert Leftwich