index_html always seems to exist
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'. 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! -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck keyserver problems? http://keyserver.kjsl.com/~jharris/keyserver.html get my key here: http://madduck.net/me/gpg/publickey the reason that every major university maintains a department of mathematicsis is that it's cheaper than institutionalizing all those people.
also sprach martin f krafft <madduck@madduck.net> [2003.05.24.0209 +0200]:
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).
Uhm, why does getattr(context.aq_explicit,'index_html') return an 'ImplicitAcquirerWrapper' object??? Didn't I tell it to *not* do acquisition with aq_explicit? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck keyserver problems? http://keyserver.kjsl.com/~jharris/keyserver.html get my key here: http://madduck.net/me/gpg/publickey "one should never trust a woman who tells her real age. if she tells that, she will tell anything." -- oscar wilde
Read the Zope Book on acquisition and the special properties of index_html. Strange as the behavior may seem, you will come to love it. On Sat, 24 May 2003, 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'.
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).
also sprach Dennis Allison <allison@sumeru.stanford.EDU> [2003.05.24.0253 +0200]:
Read the Zope Book on acquisition and the special properties of index_html. Strange as the behavior may seem, you will come to love it.
I did. http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/Acquisition.stx mentions nothing about index_html... In any case... so how do you check (from a python script) whether index_html exists or not? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck keyserver problems? http://keyserver.kjsl.com/~jharris/keyserver.html get my key here: http://madduck.net/me/gpg/publickey "when i tell a robot to get me a beer, i don't want it horsing around. i want it to get a beer." -- joseph k. engelberger
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!
At 02:09 2003-05-24 +0200, 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)
file = 'index_html' base = getattr(context, 'aq_base', context) if not hasattr(base, file): ... Dieter Maurer taught me that one.
in English: if the current folder does not have an object by the name of 'index_html', then generate a new 'Member Profile'.
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!
-- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck
keyserver problems? http://keyserver.kjsl.com/~jharris/keyserver.html get my key here: http://madduck.net/me/gpg/publickey
the reason that every major university maintains a department of mathematicsis is that it's cheaper than institutionalizing all those people.
also sprach Peter Bengtsson <mail@peterbe.com> [2003.05.27.0145 +0200]:
file = 'index_html' base = getattr(context, 'aq_base', context) if not hasattr(base, file):
doesn't work in over-the-web scripts since aq_base is not accessible. -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck keyserver problems? http://keyserver.kjsl.com/~jharris/keyserver.html get my key here: http://madduck.net/me/gpg/publickey all of you that believe in telekinetics, raise my hand!
At 08:28 2003-05-27 +0200, martin f krafft wrote:
also sprach Peter Bengtsson <mail@peterbe.com> [2003.05.27.0145 +0200]:
file = 'index_html' base = getattr(context, 'aq_base', context) if not hasattr(base, file):
doesn't work in over-the-web scripts since aq_base is not accessible.
That's right. Sorry. The create an External Method that you can use for all kinds of things. def hasattr_itself(self, object, lookingfor): base = getattr(object, 'aq_base', object) return hasattr(base, lookingfor) Then if you create this as an External Method with Id hasattr_itself you can use it in Python Scripts like this: file = 'index_html' if not context.hasattr_itself(context, file): ...
-- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck
keyserver problems? http://keyserver.kjsl.com/~jharris/keyserver.html get my key here: http://madduck.net/me/gpg/publickey
all of you that believe in telekinetics, raise my hand!
participants (4)
-
Dennis Allison -
Dylan Reinhardt -
martin f krafft -
Peter Bengtsson