[Zope] Promlem getting the current object in PythonScript
Jérôme Loisel
jerome@levinux.org
Wed, 4 Apr 2001 12:51:48 -0400
Hi!
I tried asking a question about this yesterday, and failed miserably in
describing my problem. I apologize for that. Please read on. I have taken
pains to write a very clear explanation with a code sample and precise data.
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. Read more for details.
I have a DTML Method called "adminMenu". That method is called in
standard_html_footer like so: "<dtml-var adminMenu>". It prints nothing for
anonymous users... But if the user is authenticated, it prints a
context-sensitive admin menu.
If the user is viewing a DTML Document to which he has "write
access", the admin menu prints a "Edit this document" link. There are various
other options. For many of them, I have to know which object the user is
viewing. This works fine.
But the "adminMenu" DTML Method soon grew big and cumbersome. Last week, I
decided to re-write it as a PythonScript.. The code is mostly a port (very
similar), and is called the same way: "<dtml-var adminMenu>" from the
standard_html_footer.
Yet I am now having problems getting a hold of the object which the user is
viewing. Specifically, "context" never seems to refer to DTML Documents. It
seems to ignore them like it does DTML Methods.
An example:
I use the following code to get my "debugging" information:
print " <B>File name:</B> %s<BR>" % (context.getId())
print " <B>File type:</B> %s<BR>" % (context.meta_type)
With a Folder...
viewing http://www.levinux.org/ (a Folder)
<B>File name:</B> levinux<BR>
<B>File type:</B> Folder<BR>
So far so good...
With a DTML Document...
viewing http://www.levinux.org/liens.html (a DTML Document)
<B>File name:</B> levinux<BR>
<B>File type:</B> Folder<BR>
This is not expected behavior.
My tests seem to indicate that, context.getId() and context.meta_type yield
the same result as context.this().getId() and context.this().meta_type. So I
am stumped. I am running Zope 2.3.1b2 (binary release, python 1.5.2,
linux2-x86) on a Mandrake 7.2 system.
Thanks for reading me. I hope you can help. Cheers,
Jérôme Loisel
--
Jérôme Loisel, étudiant et webmestre
Lévinux: GNU/Linux pour la communauté
http://www.levinux.org/