Loop over the different levels of PARENTS
Hi all, I want to loop over the different levels of PARENTS to get the id of the ZCatalog. The id of the ZCatalog can be dynamic this way. I've written some code to do this: def getCatalogid(self): """gets the id of the ZCatalog used for the News searchin""" level = len(self.REQUEST['PARENTS']) for item in self.REQUEST['PARENTS'][level].objectValues('ZCatalog'): catalogid = item.id level = level-1 return catalogid But I get the following error: File /var/lib/zope/Products/News/News.py, line 876, in getCatalogid (Object: newstest) IndexError: list index out of range Line 876 is the line with the 'for item in ....' expression. Does anybody know how to do this? Greetz Nico
Shouldn't level be defined as len(..)-1 ? Cornelis J. de Brabander ========================================== Department of Education, Leiden University P.O.Box 9555, NL-2300 RB Leiden +31 71 527 3422/3401 brabander@fsw.leidenuniv.nl ==========================================
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Nico de Boer Sent: dinsdag 11 juni 2002 10:13 To: zope@zope.org Subject: [Zope] Loop over the different levels of PARENTS
Hi all,
I want to loop over the different levels of PARENTS to get the id of the ZCatalog. The id of the ZCatalog can be dynamic this way.
I've written some code to do this:
def getCatalogid(self): """gets the id of the ZCatalog used for the News searchin""" level = len(self.REQUEST['PARENTS']) for item in self.REQUEST['PARENTS'][level].objectValues('ZCatalog'): catalogid = item.id level = level-1 return catalogid
But I get the following error:
File /var/lib/zope/Products/News/News.py, line 876, in getCatalogid (Object: newstest) IndexError: list index out of range
Line 876 is the line with the 'for item in ....' expression.
Does anybody know how to do this?
Greetz Nico
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
I want to loop over the different levels of PARENTS to get the id of the ZCatalog. The id of the ZCatalog can be dynamic this way.
Wouldn't it be easier to just look for "default_catalog" on the object you want to find the catalog of? The object should be catalogued under that catalog. def getCatalogid(self): """gets the id of the ZCatalog used for the News searchin""" return self.default_catalog regards Max M
I've tried the default_catalog call, but this refers to default in CatalogAwareness.py and has the value Catalog. But I want to give the site owner the opportunity to give the ZCatalog an id that I look for afterwards. Or am I using the self.default_catalog call in the wrong way? Greetz Nico
Nico de Boer wrote:
I've tried the default_catalog call, but this refers to default in CatalogAwareness.py and has the value Catalog.
But I want to give the site owner the opportunity to give the ZCatalog an id that I look for afterwards.
Or am I using the self.default_catalog call in the wrong way?
As you can see from the code:: def index_object(self): """A common method to allow Findables to index themselves.""" if hasattr(self, self.default_catalog): getattr(self, self.default_catalog).catalog_object(self, self.getPath()) A catalog aware object indexes itself in the default catalog. Just putting in a catalog with another name somewhere above the object you want indexed doesn't make the object catalog itself in that catalog. You can catalog any object in any catalog you want by using "find & index" from the catalog. But if you want the object to be automatically cataloged in another catalog than "Catalog" you need to set that objects "default_catalog" attribute. regards Max m -- "Sorry I would Really Like To Help More On This Project, But Am To Busy Doing Paid Work On A Tight Deadline" Max M
participants (3)
-
Cornelis J. de Brabander -
Max M -
Nico de Boer