'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. :) I have a form which contains the following: <input type=text name="street.address1:record"> <input type=text name="street.address2:record"> <input type=text name="street.city:record"> <input type=text name="street.state:record"> <input type=text name="street.zip:record"> To parse this data, I would ordinarily just use a dtml-with: <dtml-with street> <dtml-var address1>, etc, etc, etc </dtml-with> No problem. This, however, is where things get interesting. I'm passing the data from this form to a "confirmation" page. The data from the first form will be simply put into a bunch of "hidden" fields, where the user will be prompted to REALLY do what they were doing, or cancel back to the original form. Now, I don't want to have to re-code the confirmation page every time I add a new value to the main form, or remove an input for whatever reason. What I figured I would do is the following: <dtml-in "REQUEST.form.keys()"> <input type=hidden name="<dtml-var sequence-item>" value="<dtml-var "REQUEST.form[_['sequence-item']]">"> </dtml-in> This works fine for all the values in the form which aren't using the ":record" tag, but obviously for my address, I'll need to iterate through it. ie: <dtml-in "REQUEST.form['street'].keys()"> <input type=hidden name="street.<dtml-var sequence-item>:record" value="<dtml-var "REQUEST.form['street'][_['sequence-item']]">"> </dtml-in> ( In the original code, "street" wasn't hardcoded, and I just wrapped that statement around a dtml-try, where the except clause was my original dtml-in. ) 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']"> 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, yet somehow the <dtml-xxx> tags still work. What's going on here? I'm quite befuddled. Thanks a lot in advance for any help, and apologies again for the convoluted message. -CJ
"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
Michel Pelletier wrote:
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.
Thanks bunches for the info . . . FYI (and in case anyone else wants to do things like this), instead of actually modifying the class, I ended up just using an External Python Method (actually, it's still an XXX Method, but that'll change. *grin*) that uses item.__dict__ to find what it needs. Thanks again! -CJ
participants (2)
-
Christopher J. Kucera -
Michel Pelletier