[Zope] batch update

J Cameron Cooper jccooper at jcameroncooper.com
Tue Sep 30 22:33:01 EDT 2003


>
>
>I am trying to use DTML to allow batch update of multiple records to a mysql 
>database. 
>
>...
>I want to interate over the above method to update multiple records.  
>Basically i have five lists of data: pk_id,field1,field2,field3,field4
>i am having a hard time trying to split these lists up using DTML
>so that the first item on each list correspond to the first item of the pk_id 
>list, the second correspond to the second pk_id, and so on.
>...
>HTML Form:
>
>PK_ID  Field1 Field2 Field3 Field4
>1            f1       f2      f3           f4
>2           f1.1     f2.1   f3.1        f4.1
>
><form action="updateData" method="post">
><dtml-in getData>
>  <input type="text" name="pk_id:list" value="<dtml-var pk_id>">
>  <input type="text" name="field1:list" value="">
>  <input type="text" name="field2:list" value="">
></dtml-in>
></form>
>
This is difficult to impossible to do exactly as you ask. Why? Because 
DTML is a templating language and not a programming language, in spite 
of the fact that it allows many programming language-type constructs.

But it's easy to do in a Python Script:

#id=updateData
#arguments=pk_id,field1,field2,field3,field4
for x in range(len(pk_id)):
  context.sql_update(pk_id=pk_id[x], field1=field1[x], field2=field2[x], 
field3=field3[x], field4=field4[x])
return context.someConfirmationTemplate()

This assumes that every list is full, of course, and that the indices 
correspond, as you described.

                --jcc

-- 
"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."
(http://www.devx.com/java/editorial/15511)





More information about the Zope mailing list