[Zope] Calling Scripts with arguments from ZPT and XML-RPC

darkness darkness-gmane at caliginous.net
Tue Sep 23 20:22:02 EDT 2003


Just started playing with Zope, so apologies if this is covered in the
documentation somewhere.  I have to say that Zope is really cool.

I'm trying to post variables to a ZPT, and have that ZPT call a script
which might do something with the form variables.  Normally, if I were to
call my script from a URL I could use
'http://zopeserver/MyScript?theArg=foo', and assuming the Script named
MyScript had an argument named theArg, everything would work.  However, if
I have a ZPT called myZPT.html, I call it with a URL such as
'http://zopeserver/myZPT.html?theArg=foo', and myZPT.html contains
something like '<span tal:replace="here/MyScript" />', the parameter
theArg is not correctly passed to MyScript, and MyScript fails to execute
because it was called with too few arguments.

I'm aware I can declare MyScript to take no arguments and just access them
as context.REQUEST.theArg, but then MyScript isn't very useful if you try
to use it via XML-RPC.  I kind of want to be able to call MyScript using
either XML-RPC or internally from ZPT.  I can't declare the argument for
MyScript as 'theArg=context.REQUEST.get("theArg", None)' because it
complains that 'context' doesn't exist at that point.  I could do
something like declaring MyScript to have argument list 'theArg=None', and
then do something like 'if not theArg: theArg =
context.REQUEST.get("theArg", None)' but that's ugly.  Presumably I could
do something like 'tal:replace="python:
here.MyScript(theArg=request.theArg)"' but that seems ugly too: to include
a 'python:' TALES Python expression where (it seems to me) a TALES path
expression should do just fine.

Is there some clean way around this?  One might consider that when a call
is made to an object from ZPT, and that object has a known argument list,
ZPT/Zope should attempt to fill in the arguments to that object just as if
it were called from XML-RPC (or directly via a URL).

TIA,
darkness
--




More information about the Zope mailing list