Hi all, First time poster, long time lurker.. Ive been trying to create a product which is CatalogAware, with only some success. * I have a ZCatalog in the root of the zope installation called 'Catalog' * The class for the product inherits/mixes like thus: class myProduct(OFS.SimpleItem.Item, Persistent,.... Products.ZCatalog.CatalogAwareness.CatalogAware): * In the __init__ method, I have : self.index_object() * In any method which modifies any of the fields that are used as indexes in the catalog I also have: self.index_object() My problem is, The products will not add/delete themselves from the catalog, but when I modify the item, the catalog is updated. What am I missing about this? Regards, Adam
* In the __init__ method, I have : self.index_object()
this will not work because inside __init__ the object has no "context", it has not been seated in a container and cannot "find" things (including your catalog) through acquisition yet. add the manage_afterAdd and manage_beforeDelete hooks to you class and do indexing/unindexing in those:: def manage_afterAdd(self, item, container): """ what to do after i have been created """ self.index_object() def manage_beforeDelete(self, item, container): """ what to do before i get deleted """ self.unindex_object() those hooks get called automatically right after instantiating the object and right before it is deleted. jens
Adam Summers wrote:
Hi all,
First time poster, long time lurker..
Ive been trying to create a product which is CatalogAware, with only some success.
* I have a ZCatalog in the root of the zope installation called 'Catalog'
* The class for the product inherits/mixes like thus:
class myProduct(OFS.SimpleItem.Item, Persistent,.... Products.ZCatalog.CatalogAwareness.CatalogAware):
hi, you should rearrange your class-definition... CatalogAware must sit on the top. you wrote:
class myProduct(OFS.SimpleItem.Item, Persistent,.... Products.ZCatalog.CatalogAwareness.CatalogAware):
change this to: class myProduct(Products.ZCatalog.CatalogAwareness.CatalogAware, OFS.SimpleItem.Item, Persistent): cheers, maik
participants (3)
-
Adam Summers -
Jens Vagelpohl -
Maik Jablonski