[Zope] REQUEST weirdness . . .
Michel Pelletier
michel@digicool.com
Fri, 31 Mar 2000 15:54:19 -0800
"Christopher J. Kucera" wrote:
>
> 'ello.
>
> Bear with me on this one; I'm having worlds of problems coming up
> with any kind of coherent way of expressing the problem. :)
>
>
> This code doesn't work. Upon closer inspection, the following line
> was the culprit:
>
> <dtml-in "REQUEST.form['street'].keys()">
>
> Upon even closer inspection, *none* of the dictionary functions would
> work. Not even <dtml-var "REQUEST.form['street']['address1']">
I know that in the CVS now, record objects support the Python mapping
interface (which is what you're trying to do) but before that, and I
think this is the case for the 2.1.x branch, this wasn't supported, and
you needed to access the object by attribute only. This makes what you
want to do in DTML pretty impossible (but not impossible from python).
I guess you can try waiting for the next main trunk release, or you can
modify your record objects to support a mapping interface just like the
CVS does. It's a very simple class in the
lib/python/ZPublisher/HTTPRequest.py module. This is probably the
simplest solution to your problem.
> Then I decided it was time to just see exactly what was in the object.
> <dtml-var "REQUEST.form['street']"> yielded the following results
> (I had just entered sequential numbers for all five inputs):
>
> address1: 1, address2: 2, city: 3, state: 4, zip: 5
>
> Here's the output of <dtml-var "REQUEST.form">:
>
> {'street': address1: 1, address2: 2, city: 3, state: 4, zip: 5, 'submit':
> 'submit'}
>
> The original <dtml-with> code still works, as does
> <dtml-var "street.address1">. I've also tried using getitem:
>
> <dtml-var "_.getitem('street')['address1']">
>
> I'm quite confused. It would appear that "street" really *isn't*
> a dictionary at all,
Nope. In your case it's an object with _instance attributes_ that
contain your values.
-Michel