[Zope] Modifying a Dictionaries in an Extenal Method
Tino Wildenhain
tino at wildenhain.de
Sun Jun 5 12:53:46 EDT 2005
Am Sonntag, den 05.06.2005, 00:05 -0500 schrieb Edward Huixquic:
> Thanks Dieter for your kind reply,
>
> Here is a complete (a bit long, sorry for that) example of what is
> happening, here are some code pieces that shows this behavior:
>
> DTML:
> --------------------------------------------------
> <HTML>
> <BODY>
> <dtml-if process >
> <dtml-in fields mapping>
> <dtml-call "pyUpdate(REQUEST)">
> <dtml-var balance>
> </dtml-in>
> <dtml-var REQUEST>
> </dtml-if>
> <form name="input_form" "./test1">
> Name: <input type="text" name="fields.name:records" value="Mickey"><br>
> Lastname:<input type="text" name="fields.lastname:records" value="Mouse"><br>
> Account Balance:<input type="text" name="fields.balance:records"
> value="1000"><br>
> <br><br>
> Name: <input type="text" name="fields.name:records" value="Donald"><br>
> Lastname:<input type="text" name="fields.lastname:records" value="Duck"><br>
> Account Balance:<input type="text" name="fields.balance:records"
> value="2000"><br>
> <input type="submit" value="process" name="process">
> </form>
> </BODY>
> </HTML>
> ----------------------------------------------
> Python External Method:
> def pyUpdate(self,REQUEST):
> for item in range(len(self.REQUEST['fields'])):
> self.REQUEST['x']=self.REQUEST['fields'][0]
> self.REQUEST['y']=self.REQUEST['fields'][1]
> # self.REQUEST['fields'][0]['balance']=5000 <-----I will
> refer to this as first line
> # self.REQUEST['y']['balance']=5000 <-------- this would
> be the second line
> return self.REQUEST
> -------------------------------------------
> Output of form after pressing the "process" button WITH both lines
> commented out in the External method, as show above (cut from the
> whole REQUEST output):
>
> 1000 2000
> form
> process 'process'
> fields [{'balance': '1000', 'lastname': 'Mouse', 'name': 'Mickey'},
> {'balance': '2000', 'lastname': 'Duck', 'name': 'Donald'}]
> <cut stuff>
> fields [{'balance': '1000', 'lastname': 'Mouse', 'name': 'Mickey'},
> {'balance': '2000', 'lastname': 'Duck', 'name': 'Donald'}]
> y {'balance': '2000', 'lastname': 'Duck', 'name': 'Donald'}
> x {'balance': '1000', 'lastname': 'Mouse', 'name': 'Mickey'}
>
> So, fields behaves as a list and X and Y are dictionaries, right?
No. They look like dictionaries, but they are not dictionaries.
You used :records, which gives you lists of record objects.
You can copy to a real dictionary to do what you want.
More information about the Zope
mailing list