[Zope] try clause in external method
Garry Saddington
garry at schoolteachers.co.uk
Mon Apr 14 15:19:49 EDT 2008
I have the following external method which takes an input .csv file and enters
the data into a database by calling a ZSQL method. There may be errors in the
input file and so I am trying to catch them and insert each bad row in a
different table. The errors are detected by table constraints on the table
definition and should be reported by the Psycopg connector. However no
correct rows are entered and only the last error row is entered. Can anyone
see what I am doing wrong in this script?
def timetabler(self,REQUEST):
import csv,string
f=REQUEST.form["TTEXPORT.CSV"]
from cStringIO import StringIO
filebody=StringIO(f.read())
r =
csv.DictReader(filebody("day","periodstart","periodend" ,"year","teachgroup","teacher" ,"subject" ,"set" ,"room"))
for row in r:
try:
self.insertintoiclasses(**row)
except:
self.insertimporterrors(**row)
dtmlMethodName="manage_import_from_timetabler"
return self[dtmlMethodName](self,self.REQUEST)
regards
garry
More information about the Zope
mailing list