[Zope] How to catalog all objects inherited from a certain class?

Dieter Maurer dieter@handshake.de
Wed, 30 Oct 2002 20:27:52 +0100


Igor Elbert writes:
 > I am looking for a way to catalog all objects inherited from my class.
 > Objects may have different meta_types so I can't use
 > obj_metatypes=['MyClass'].
 > 
 > I found that ZCatalog uses ZopeFind for the search. ZopeFind has a 
 > parameter obj_expr that gets evaluated on the fly. I would like to 
 > say something like
 > ZopeFind(..., obj_expr='isinstance(self, MyClass)' )
 > but I don't know how.
"isinstance" is not available in TTW code (it would not work).

One trick, often used in Zope is to provide indicating attributes,
e.g. "isPrincipiaFolderish" indicates a Zope Folder (and its
derivatives).

  You must be careful, that the attribute is not acquired.
  Safely, this is only possible in an External Method.
  You can appriximate it in TTW code with

      obj_expr="_.hasattr(aq_explicit,'mySpecialAttribute')"

The alternative is to use an External Method "checkMyClass" in

      obj_expr="checkMyClass(this())"

with

  def checkMyClass(self):
    from Acquisition import aq_base
    return isinstance(aq_base(self),MyClass)



Dieter