[Zope] index_html always seems to exist

Dylan Reinhardt zope@dylanreinhardt.com
23 May 2003 18:38:56 -0700


On Fri, 2003-05-23 at 17:09, martin f krafft wrote:
> i have a python script doing the following:
> 
>   file = 'index_html'
>   if not hasattr(context.aq_explicit, file):
>     context.invokeFactory('Member Profile', id=file, title=file)
> 
> in English:
>   if the current folder does not have an object by the name of
>   'index_html', then generate a new 'Member Profile'.

Ah, but that's not what your Python code asks for.  

Your code checks if the folder has an *attribute* called 'index_html'. 
Thing is, *all* folders have an index_html attribute.

What you *want* to do is check if objectIds() of your folder contains
'index_html'. That should do the trick.

HTH,

Dylan

> 
> This works beautifully whenever file is set to something that's not
> 'index_html'; the file gets added if and only if there isn't one
> yet.
> 
> However, in the case of index_html, it always seems to exist, even
> if there is no index_html in the current folder (and yes, I have
> verified that context is the right folder).
> 
> What am I doing wrong?
> 
> Thanks!