python script returning DTMLMethod problem
Hello All: My earlier question (form/script problem) regarding passing variables from a form to a python script was successfully solved with the suggestion by Malik Jablonski to include this in the script: request = container.REQUEST myfile=request.myfile fname=request.fname Thanks Malik. But I have a further issue in that I wish the python script to return a DTMLMethod that calls dtml-tree to display the contents of a folder. I cannot find any references to python scripts returning DTMLMethods or Documents and the suggestions following do not work, I think because of namespace problem.
must pass the "positional" parameters. you coded:
return context.avc.showFiles() should be something like this: return context.avc.showFiles(None,context.REQUEST)
and
I've had some success with equivalents of return context.avc.showFiles(context) - then your DTML Method will have a context and can find 'avc' in it.
The form, script and DTMLMethod are all in the same folder object and 'avc' is the container object (folder) for that folder but the error I get is Error Type: KeyError Error Value: avc Even if I have a single line script calling this DTMLMethod (take the form out of the loop) I get the same error. Does acquistion work with python scripts? And can anyone offer a way for a python script to return DTML methods or documents? Even if the script: return context.showUploadRequests() calling a simple DTML method: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer> fails with error: Error Type: KeyError Error Value: standard_html_header Tom Germaine
On Wed, 7 Aug 2002, Tom Germaine wrote:
Even if the script: return context.showUploadRequests()
calling a simple DTML method: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer>
fails with error: Error Type: KeyError Error Value: standard_html_header
This one should work as return context.showUploadRequests(context) Certainly I have written lots of Python scripts which include the line print context.standard_html_header(context) David
Thanks, this solution solves the problem of script returning DTMLMethod: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer> but this solution does not help me with my original problem of returning this DTMLMethod: <html> <head></head> <body> <h2>AVC files:</h2> <dtml-call "REQUEST.set('expand_all',_.int(1))"> <dtml-tree avc branches_expr="objectValues(['Folder','DTML Document'])" sort=id> <dtml-if "meta_type=='Folder'"> <dtml-if expr="title == ''"> <dtml-else> <h3><dtml-var title ></h3> </dtml-if> </dtml-if> <dtml-if "meta_type=='DTML Document'"> <dtml-if "title == ''"> <dtml-else> <li><dtml-var id>:: <A HREF="&dtml-absolute_url;" target=display> <dtml-var title></a></li> </dtml-if> </dtml-if> </dtml-tree> </body> </html> with error message Error Type: KeyError Error Value: URL Any further suggestions would be appreciated. Tom On 7 Aug 2002, at 16:24, DA Loeffler wrote:
On Wed, 7 Aug 2002, Tom Germaine wrote:
Even if the script: return context.showUploadRequests()
calling a simple DTML method: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer>
fails with error: Error Type: KeyError Error Value: standard_html_header
This one should work as return context.showUploadRequests(context)
Certainly I have written lots of Python scripts which include the line print context.standard_html_header(context)
David
hi tom, have a look at http://www.zopelabs.com/cookbook/992031125 for the correct syntax calling a DTML-Method from a PythonScript. must be something like this: dtmlMethod(context, context.REQUEST) or if _ is bound to the (Script) Python in the bindings tab dtmlMethod(context, _) I guess you need the last one [submitting the whole Namespace to your DTMLMethod]! calling dtmlMethod(context) works only in some special cases, but it is not correct at all... greetings, maik Tom Germaine wrote:
Thanks, this solution solves the problem of script returning DTMLMethod: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer> but this solution does not help me with my original problem of returning this DTMLMethod: <html> <head></head> <body> <h2>AVC files:</h2> <dtml-call "REQUEST.set('expand_all',_.int(1))"> <dtml-tree avc branches_expr="objectValues(['Folder','DTML Document'])" sort=id> <dtml-if "meta_type=='Folder'"> <dtml-if expr="title == ''"> <dtml-else> <h3><dtml-var title ></h3> </dtml-if> </dtml-if>
<dtml-if "meta_type=='DTML Document'"> <dtml-if "title == ''"> <dtml-else> <li><dtml-var id>:: <A HREF="&dtml-absolute_url;" target=display> <dtml-var title></a></li> </dtml-if> </dtml-if> </dtml-tree> </body> </html>
with error message Error Type: KeyError Error Value: URL
Any further suggestions would be appreciated.
Tom
On 7 Aug 2002, at 16:24, DA Loeffler wrote:
On Wed, 7 Aug 2002, Tom Germaine wrote:
Even if the script: return context.showUploadRequests()
calling a simple DTML method: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer>
fails with error: Error Type: KeyError Error Value: standard_html_header
This one should work as return context.showUploadRequests(context)
Certainly I have written lots of Python scripts which include the line print context.standard_html_header(context)
David
-- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
DA Loeffler writes:
return context.showUploadRequests(context)
Certainly I have written lots of Python scripts which include the line print context.standard_html_header(context) This works only as long you do not try to reference request variables directly.
Dieter
Tom Germaine writes:
But I have a further issue in that I wish the python script to return a DTMLMethod that calls dtml-tree to display the contents of a folder. I cannot find any references to python scripts returning DTMLMethods or Documents and the suggestions following do not work, I think because of namespace problem. Bah, the mailing list is overfull of them...
must pass the "positional" parameters. ... not too bad! you coded:
return context.avc.showFiles() should be something like this: return context.avc.showFiles(None,context.REQUEST) Almost, better:
client= context.avc return client.showFiles(client,context.REQUEST) Dieter
participants (4)
-
DA Loeffler -
Dieter Maurer -
Maik Jablonski -
Tom Germaine