[Zope] Loop over the different levels of PARENTS

Cornelis J. de Brabander brabander@fsw.LeidenUniv.nl
Tue, 11 Jun 2002 12:40:36 +0200


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 )
>