[Zope] Catalog-aware ZClass not getting indexed?

Darran Edmundson Darran.Edmundson@anu.edu.au
Tue, 15 Feb 2000 16:17:23 +1100


Hello Zopesters,

This problem is mission-critical and seemingly non-trivial.
If you've written me off as posting FAQs, I beseech you
to read on at least one more time ...

My through-the-web-defined catalog-aware ZClass works perfectly
through the web interface.  Now I'm trying to create instances
with an external method.  These programmatically created
instances are being created but are not showing up in my
ZCatalog.  Now before you shift your mind back into neutral
and (if you're feeling friendly) have your mailer auto-send
me the answer to FAQ #27b, continue to read on ...

As per the comment in CatalogAwareness.py:

    Note that if your class or ZClass subclasses CatalogAware,
    it will only catalog itself when it is added or copied in
    Zope.  If you make changes to your own object, you are
    responsible for calling your object's index_object method.

and Tazzzz's How-To on adding ZClass instances via python:

    http://www.zope.org/Members/tazzzzz/addZClasses

snippets from my external method read,

    instance = archive.Control_Panel.Products.myClass(id)
    instance.id = id

    # attach new instance to container object
    container._setObject(id, instance)

    # as per Alex R's HowTo,
    #  http://www.zope.org/Members/AlexR/CatalogAware
    # make it catalog-aware with custom catalog name
    instance.unindex_object()
    instance.manage_editCataloger('myCatalog')
    instance.index_object()

So far, so good.  Zope doesn't choke on my method, new
instances get created and seem well behaved, but they
are not showing up in myCatalog.  And no wonder, adding
a few debugging print statements into CatalogAwareness.py

    def index_object(self):
        """A common method to allow Findables to index themselves."""
        print 'INDEX_OBJECT:  ', self.id, self.default_catalog,
hasattr(self, self.default_catalog)
        if hasattr(self, self.default_catalog):
            print '      whoopee, looks like we get to index ', self.id
            getattr(self, self.default_catalog).catalog_object(self,
self.url())

    def unindex_object(self):
        """A common method to allow Findables to unindex themselves."""
        print 'UNINDEX_OBJECT:  ', self.id, self.default_catalog,
hasattr(self, self.default_catalog)
        if hasattr(self, self.default_catalog):
            print '      unindexing ', self.id
            getattr(self, self.default_catalog).uncatalog_object(self.url())

my instance never makes it past the hasattr(self, self.default_catalog)
test as witnessed by the following (bracketed comments are mine):

   INDEX_OBJECT:   newinstance Catalog 0      (try to add newinstance to
default catalog)
   UNINDEX_OBJECT:   newinstance Catalog 0    (try to remove it)
   INDEX_OBJECT:   newinstance myCatalog 0  (try to add to custom catalog)


Can someone pin down why myClass works perfectly through the management
interface but not via this external method?  Specifically what is
missing in my external method that is causing my instance to not get
past the hasattr test?  Thanks very much for any help you can provide.

Cheers,
Darran.