Hi! Evan Simpson -- Mercredi 04 Avril 2001 13:58:
From: "Jérôme Loisel" <jerome@levinux.org>
My basic question is this: I have code which is called from standard_html_footer. When that code was a DTML Method, I used this(). Now that this code is a PythonScript, how do I access the same object? "context" and "context.this()" do not work reliably.
In this sort of situation, "context" is very different from "this()".
Short answer:
Use the Script's Bindings tab to bind the caller's namespace to "_" (or some other name) and use _["this"] to refer to the document.
Hm... I really appreciate the info, but I am having *really* weird problems now. You can look at my script's source (the bound version). It is fairly readable and commented in English. It is all really simple stuff. http://zope.levinux.org/adminMenu.txt The weird problem is that binding namespace to _ radically changed my script's behavior. The first thing I noticed was that anonymous users were no longer allowed to view the site. Considering that my script starts with the following code... user = context.REQUEST.AUTHENTICATED_USER if user.getId() == None: return "" I find that weird. I can tell that the return does indeed work because nothing at all gets printed. Yet commenting out the three lines towards the end which refer to owner_info once again allower anonymous users to view the site. You can read the specfic error message I got on that problem here: http://zope.levinux.org/error1.html And remember that none of that happens if namespace is not bound... Having commented out the owner_info code, I was still not out of the woods. Authenticated AND unauthenticated users get errors when viewing any page: TypeError: no arguments expected. You can read the error message here: http://zope.levinux.org/error2.html Again, let me remind you that these errors only occur when I try to bind namespace to _. Am I going nuts or is this not expected behavior? Thanks in advance for all your help. Cheers, Jérôme PS: Fun with AUTHENTICATED_USER I ran some tests to see what happened to AUTHENTICATED_USER in PythonScript when binding the namespace. The sort answer is: nothing. Yet the following code yields very different behavior from the code in adminMenu.py: user = context.REQUEST.AUTHENTICATED_USER print "Hello!" print user.getId() return printed I get a Zope error: TypeError, call of non-function (type list). I find this very puzzling. You can see the full error message here: http://zope.levinux.org/error3.html The following code, however, raises no error: user = context.REQUEST.AUTHENTICATED_USER print "Hello!" print user return printed But for anonymous user, it returns "Anonymous User" instead of None. Yet trying to use if user == "Anonymous User" in Python code does not work. It raises no error, but always evaluates to false. I thought I was starting to know my way around Zope. But this is as confusing as it gets. Meesa not understand. -- Jérôme Loisel, étudiant et webmestre Lévinux: GNU/Linux pour la communauté http://www.levinux.org/