Calling Scripts with arguments from ZPT and XML-RPC
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 --
darkness wrote:
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).
Is this what you are looking for? <span tal:replace="python:here.MyScript(request['theArg'])" /> the same as <span tal:define="theArg request/theArg" tal:replace="python:here.MyScript(theArg)" /> regards Max M
On Wed, 24 Sep 2003 08:26:04 +0200, Max M wrote:
Is this what you are looking for?
<span tal:replace="python:here.MyScript(request['theArg'])" />
the same as
<span tal:define="theArg request/theArg" tal:replace="python:here.MyScript(theArg)" />
regards Max M
Unfortunately, no. I was really hoping that there was some implicit manner by which request variables (form variables) were passed to scripts when called via a TALES path. I was hoping to avoid "python:" paths, with the end goal of having no "code" in the template. darkness
darkness wrote:
Unfortunately, no. I was really hoping that there was some implicit manner by which request variables (form variables) were passed to scripts when called via a TALES path. I was hoping to avoid "python:" paths, with the end goal of having no "code" in the template.
No,no,no!!! That leads to the dark path. Explicit is better than implicit. It is so much easier to follow the flow of data when it is stated explicitly. Something like PHPs habbit of popping up variable in the namespace as they magically appear in the request is evil. We have it in dtml too. Pagetemplates are much easier to read, exactly because it is explicit where the variables comes from. regards Max M
darkness wrote at 2003-9-23 20:22 -0400:
... 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.
You may try: Parameters for "MyScript": param1=None, param2=None, ... Code for "MyScript": r= container.REQUEST if param1 is None: param1= r['param1'] if param2 is None: param2= r['param2'] ... Dieter
participants (3)
-
darkness -
Dieter Maurer -
Max M