[Zope] client argument to python function calls?
Randall Kern
randy@teamkern.net
Sun, 26 Nov 2000 20:17:13 -0800
This is a multi-part message in MIME format.
------=_NextPart_000_0EBD_01C057E5.DCE66D70
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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...
Thanks,
-Randy
------=_NextPart_000_0EBD_01C057E5.DCE66D70
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>I'm trying to emulate some DTML methods =
with python=20
code in my (python) product.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Let's say I have two Python classes, =
one named Foo,=20
the other Bar. Something like this:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>class Foo(Folder.Folder, Persistent,=20
Implicit):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> meta_type =3D =
"Foo"</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> def magic(self,=20
client=3DNone):</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> "magic=20
method!"</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =
if client =3D=3D=20
None:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
client =3D self</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =
return=20
client.magic_word</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>class Bar(Folder.Folder, Persistent,=20
Implicit):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> meta_type =3D=20
"Bar"</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> def __init__(self,=20
id):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
self.id =3D=20
id</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
self.magic_word =3D 'Alacazam!"</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Now I create a structure like this in=20
Zope:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>/</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
foo (instance=20
of the Foo class)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
bar (instance=20
of the Bar class)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Now if I goto /bar/foo/magic, I see the =
magic=20
word. However, I would also like to use /foo/bar/magic, and also =
receive=20
the magic word. This latter case doesn't work, the magic_word =
isn't=20
set.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>In fact, the "client" argument is never =
anything=20
but None.</FONT></DIV>
<DIV> </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> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-Randy</FONT></DIV></BODY></HTML>
------=_NextPart_000_0EBD_01C057E5.DCE66D70--