[Zope] calling dtmlMethod from python

Chris Kratz chris.kratz@vistashare.com
Tue, 30 Oct 2001 11:26:40 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_005E_01C16135.BED6E580
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I ran into this awhile back.  Try this:

context.scReport(None, _)

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:

context.scReport(None, _, MsgToUser=3D'Hello')

Inside your dtml-method you could do a=20

<dtml-var MsgToUser>

This is very usefull to passing stuff around without cluttering up your =
REQUEST namespace.

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:

methodToCall =3D _.getitem('methodName') # Find object via acquisition =
and get handle on it.
print methodToCall(None, _)  # Call the method and print the results.

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').

Hope that helps.

-Chris


------------------------------
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_005E_01C16135.BED6E580
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 http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Courier New" size=3D2>I ran into this awhile =
back.&nbsp; Try=20
this:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>context.scReport(None, =
_)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</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.&nbsp; For example with the following call:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&lt;dtml-var =
MsgToUser&gt;</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Another little trick I =
learned.&nbsp; Want=20
to find an object via acquisition and then call it?&nbsp; I found that =
the=20
following worked in a python script:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</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, =
_)&nbsp; # Call=20
the method and print the results.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>This is really usefull if you =
generate the=20
method name as I do depending on the request.&nbsp; ie methodToCall =3D=20
_.getitem(someStrVar + 'form') will concatenate the two strings and then =
look=20
for that object in the namespace.&nbsp; 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>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Hope that helps.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>-Chris</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</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"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-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 title=3Dshane.osullivan@engitech.ie=20
  href=3D"mailto:shane.osullivan@engitech.ie">Shane O'Sullivan</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dzope@zope.org=20
  href=3D"mailto:zope@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 zope=20
  and trying to write a simple python script to handle some =
logic&nbsp;which=20
  will then call a dtml method. I'm calling the method as=20
  such:&nbsp;&nbsp;&nbsp; context.scReport()</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>The error I'm getting back is =
<STRONG>Error Type:=20
  =
KeyError</STRONG><BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 =
size=3D2>Shaneo</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_005E_01C16135.BED6E580--