[Zope] calling dtmlMethod from python
Shane O'Sullivan
shane.osullivan@engitech.ie
Tue, 30 Oct 2001 17:04:21 -0000
This is a multi-part message in MIME format.
------=_NextPart_000_0041_01C16164.EB40C940
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Chris,
thanks for your help...I tried your suggestion but it has now =
returned the error
Error Type: NameError
Error Value: global name '_' is not defined
If you have time, would you mind explaining what "_" represents? Is this =
defined in a library that we mightn't have included?
Thanks again,
Shaneo
----- Original Message -----=20
From: Chris Kratz=20
To: Shane O'Sullivan ; zope@zope.org=20
Sent: Tuesday, October 30, 2001 4:26 PM
Subject: Re: [Zope] calling dtmlMethod from python
I ran into this awhile back. Try this:
=20
context.scReport(None, _)
=20
Interestingly enough, I also learned that you can pass things into a =
dtml-method and they become available to use internally. For example =
with the following call:
=20
context.scReport(None, _, MsgToUser=3D'Hello')
=20
Inside your dtml-method you could do a=20
=20
<dtml-var MsgToUser>
=20
This is very usefull to passing stuff around without cluttering up =
your REQUEST namespace.
=20
Another little trick I learned. Want to find an object via =
acquisition and then call it? I found that the following worked in a =
python script:
=20
methodToCall =3D _.getitem('methodName') # Find object via acquisition =
and get handle on it.
print methodToCall(None, _) # Call the method and print the results.
=20
This is really usefull if you generate the method name as I do =
depending on the request. ie methodToCall =3D _.getitem(someStrVar + =
'form') will concatenate the two strings and then look for that object =
in the namespace. If you do this kind of lookups, you should probably =
also check for existence before calling it, ie _.has_key(someStrVar + =
'form').
=20
Hope that helps.
=20
-Chris
=20
=20
------------------------------
Chris Kratz
chris.kratz@vistashare.com
----- Original Message -----=20
From: Shane O'Sullivan=20
To: zope@zope.org=20
Sent: Tuesday, October 30, 2001 11:13 AM
Subject: [Zope] calling dtmlMethod from python
Can anyone please help with this, I'm new to zope and trying to =
write a simple python script to handle some logic which will then call a =
dtml method. I'm calling the method as such: context.scReport()
The error I'm getting back is Error Type: KeyError
Error Value: =
standard_html_header
standard_html_header is being called from the scReport method which =
suggests the scReport method is being invoked but why are we getting an =
error?? Any suggestions, TIA
Shaneo
------=_NextPart_000_0041_01C16164.EB40C940
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Chris,</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> thanks=20
for your help...I tried your suggestion but it has now returned the=20
error</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<P><STRONG>Error Type: NameError</STRONG><BR><STRONG>Error Value: global =
name=20
'_' is not defined</STRONG><BR></P>
<P>If you have time, would you mind explaining what "_" represents? Is =
this=20
defined in a library that we mightn't have included?</P>
<P>Thanks again,</P>
<P>Shaneo</P>
<P> </P>
<P> </P></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A href=3D"mailto:chris.kratz@vistashare.com"=20
title=3Dchris.kratz@vistashare.com>Chris Kratz</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20
href=3D"mailto:shane.osullivan@engitech.ie"=20
title=3Dshane.osullivan@engitech.ie>Shane O'Sullivan</A> ; <A=20
href=3D"mailto:zope@zope.org" title=3Dzope@zope.org>zope@zope.org</A> =
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, October 30, 2001 =
4:26=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Zope] calling =
dtmlMethod=20
from python</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>I ran into this awhile =
back. Try=20
this:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>context.scReport(None, =
_)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Interestingly enough, I also =
learned that=20
you can pass things into a dtml-method and they become available to =
use=20
internally. For example with the following call:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>context.scReport(None, _,=20
MsgToUser=3D'Hello')</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Inside your dtml-method you =
could do a=20
</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2><dtml-var =
MsgToUser></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>This is very usefull to =
passing stuff=20
around without cluttering up your REQUEST namespace.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Another little trick I =
learned. =20
Want to find an object via acquisition and then call it? I found =
that=20
the following worked in a python script:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>methodToCall =3D =
_.getitem('methodName') #=20
Find object via acquisition and get handle on it.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>print methodToCall(None, =
_) # Call=20
the method and print the results.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>This is really usefull if you =
generate=20
the method name as I do depending on the request. ie =
methodToCall =3D=20
_.getitem(someStrVar + 'form') will concatenate the two strings and =
then look=20
for that object in the namespace. If you do this kind of =
lookups, you=20
should probably also check for existence before calling it, ie=20
_.has_key(someStrVar + 'form').</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Hope that helps.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>-Chris</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV>------------------------------<BR>Chris Kratz<BR><A=20
=
href=3D"mailto:chris.kratz@vistashare.com">chris.kratz@vistashare.com</A>=
<BR></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; =
MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A href=3D"mailto:shane.osullivan@engitech.ie"=20
title=3Dshane.osullivan@engitech.ie>Shane O'Sullivan</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:zope@zope.org"=20
title=3Dzope@zope.org>zope@zope.org</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, October 30, =
2001 11:13=20
AM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Zope] calling =
dtmlMethod from=20
python</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Can anyone please help with this, =
I'm new to=20
zope and trying to write a simple python script to handle some=20
logic which will then call a dtml method. I'm calling the =
method as=20
such: context.scReport()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The error I'm getting back is =
<STRONG>Error=20
Type:=20
=
KeyError</STRONG><BR><STRONG> &n=
bsp; &nb=
sp; &nbs=
p; Error=20
Value: standard_html_header</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>standard_html_header is being =
called from the=20
scReport method which suggests the scReport method is being invoked =
but why=20
are we getting an error?? Any suggestions, TIA</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>Shaneo</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0041_01C16164.EB40C940--