[Zope] client argument to python function calls?

Randall Kern randy@teamkern.net
Mon, 27 Nov 2000 15:00:15 -0800


This is a multi-part message in MIME format.

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

Figured this out, with the zope-dev archives.

In case anyone else bumps into the same thing, the FunctionTemplate =
class at http://www.zope.org/Members/htrd/howto/FunctionTemplate is very =
helpful.
-Randy
  ----- Original Message -----=20
  From: Randall Kern=20
  To: zope@zope.org=20
  Sent: Sunday, November 26, 2000 8:17 PM
  Subject: [Zope] client argument to python function calls?


  I'm trying to emulate some DTML methods with python code in my =
(python) product.

  Let's say I have two Python classes, one named Foo, the other Bar.  =
Something like this:

  class Foo(Folder.Folder, Persistent, Implicit):
      meta_type =3D "Foo"

      def magic(self, client=3DNone):
          "magic method!"

          if client =3D=3D None:
              client =3D self

          return client.magic_word

  class Bar(Folder.Folder, Persistent, Implicit):
      meta_type =3D "Bar"

      def __init__(self, id):
          self.id =3D id
          self.magic_word =3D 'Alacazam!"


  Now I create a structure like this in Zope:

  /
      foo    (instance of the Foo class)
      bar    (instance of the Bar class)

  Now if I goto /bar/foo/magic, I see the magic word.  However, I would =
also like to use /foo/bar/magic, and also receive the magic word.  This =
latter case doesn't work, the magic_word isn't set.

  In fact, the "client" argument is never anything but None.

  This is a facet of Zope I still don't quite understand...
  =20
  Thanks,
  -Randy

------=_NextPart_000_1016_01C05882.BFBCFB40
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.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Figured this out, with the zope-dev=20
archives.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>In case anyone else bumps into the same =
thing,=20
</FONT><FONT face=3DArial size=3D2>the FunctionTemplate class at <A=20
href=3D"http://www.zope.org/Members/htrd/howto/FunctionTemplate">http://w=
ww.zope.org/Members/htrd/howto/FunctionTemplate</A>=20
is very helpful.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-Randy</FONT></DIV>
<BLOCKQUOTE=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:randy@teamkern.net" =
title=3Drandy@teamkern.net>Randall Kern</A>=20
  </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> Sunday, November 26, 2000 =
8:17=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Zope] client argument =
to python=20
  function calls?</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>I'm trying to emulate some DTML =
methods with=20
  python code in my (python) product.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Let's say I have two Python classes, =
one named=20
  Foo, the other Bar.&nbsp; Something like this:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>class Foo(Folder.Folder, Persistent,=20
  Implicit):</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; meta_type =3D =
"Foo"</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; def magic(self,=20
  client=3DNone):</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "magic=20
  method!"</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
if client=20
  =3D=3D None:</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

  &nbsp;&nbsp;&nbsp; client =3D self</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
return=20
  client.magic_word</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>class Bar(Folder.Folder, Persistent,=20
  Implicit):</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; meta_type&nbsp;=3D =

  "Bar"</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; def __init__(self, =

  id):</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
self.id =3D=20
  id</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

  self.magic_word =3D 'Alacazam!"</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Now I create a structure like this in =

  Zope:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>/</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
foo&nbsp;&nbsp;&nbsp;=20
  (instance of the Foo class)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
bar&nbsp;&nbsp;&nbsp;=20
  (instance of the Bar class)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Now if I goto /bar/foo/magic, I see =
the magic=20
  word.&nbsp; However, I would also like to use /foo/bar/magic, and also =
receive=20
  the magic word.&nbsp; This latter case doesn't work, the magic_word =
isn't=20
  set.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>In fact, the "client" argument is =
never anything=20
  but None.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>This is a facet of Zope I still don't =
quite=20
  understand...</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>-Randy</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_1016_01C05882.BFBCFB40--