[Zope] Update Multiple Records
David
bluepaul at earthlink.net
Tue Mar 21 13:33:41 EST 2006
Andrew Milton wrote:
>+-------[ April Lekin ]----------------------
>| Hi,
>| I have a web page that goes to a database and pulls out a bunch of records
>| for display and then I gave each field the ability to modify except the
>| primary ID.
>|
>| The problem I'm having is how do I make each field unique so that I can go
>| back to the database and update the record. I was thinking about putting
>| the primary key in the name like:
>| <input type="text" name="lname + ID" value="">
>| <input type="text" name="fname + ID" value="">
>|
>| but I don't know how to do that with python.
>|
>| Is there another way to update a bunch of records at once?
>
><input type="text" name="item.lname:records" value="">
><input type="text" name="item.fname:records" value="">
>
>
>You'll get an a REQUEST object called item which is a list of records with
>each attribute set inside it.
>
>
>
Hey Andrew,
Cool tip. I never took advantage of this stuff:
<form action="pyUpdateRecords" name="theform" method="post">
<input type="text" name="items.id:records" value="023">
<input type="text" name="items.lname:records" value="smith">
<input type="text" name="items.fname:records" value="frank">
<input type="text" name="items.id:records" value="583">
<input type="text" name="items.lname:records" value="gates">
<input type="text" name="items.fname:records" value="bill">
When this form is summited it puts the following array of dictionaries
in the request:
items[{'fname': 'frank', 'id': '023', 'lname': 'smith'}, {'fname':
'bill', 'id': '583', 'lname': 'gates'}]
Then the records can be updated like so:
#module pyUpdateRecords
for item in request.get('items',[]).
context.SQL.upDateMyRecs(id=item['id'],lname=item['lname'] ....)
# now return a screen
return context.SomeTemplate(context,request)
David
More information about the Zope
mailing list