[Zope] Re: converting string to dict ?
Duncan Booth
duncan@rcp.co.uk
Wed, 11 Apr 2001 14:14:55 +0100
> My conclusion thus far is that I should stick with External Python
> Methods and be happy. But I have this peverse curiosity to make it
> work in Python Script also. The Docs say that eval() is not allowed in
> Scipts(Python). Is this the trouble I am having?
I am somewhat confused as to exactly the effect you are trying to achieve, but
here are a few suggestions.
When you retrieve a URL in Zope the query string is automatically converted
into a dictionary acessible as REQUEST.form, or in the case of a PythonScript
as context.REQUEST.form. If you want to pass an arbitrary dictionary to your
script through a URL then the best way is usually just to imitate a form that had
the dictionary elements as fields.
To pass a dictionary from DTML you can build the dictionary and pass it in
directly, not as a string but as a dictionary, or you can use keyword arguments.
For example if you define a PythonScript like this:
## Script (Python) "ShowDict"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=**dict
##title=
##
from Products.PythonScripts.standard import html_quote
dict = dict or context.REQUEST.form
return html_quote(`dict`)
Then you can retrieve
http://yourhost/ShowDict?message=Do+you+understand+now%3f&name=Zope
+Lover&status=done
or from inside DTML you can do <dtml-var ShowDict> if you want all of the
request arguments passed through, and
<dtml-var expr="ShowDict(message='Do you understand now?',
name='zope Lover', status='done')">
to pass the arguments explicitly. Once inside ShowDict the effect is the same.
For dictionary elements other than strings you can use type modifiers on the
field names. e.g. http://yourhost/ShowDict?x:int=5
Does this help any?
--
Duncan Booth duncan@rcp.co.uk