Now i have an iterable file for the csv module in this code: def students(self,REQUEST): import csv f=REQUEST.form["students.csv"] from cStringIO import StringIO filebody=StringIO(f.read()) reader = csv.DictReader(filebody,("firsname","surname", "year","form","gender")) for row in reader: self.writestudents(row) Writestudents is a zsql method with the following body: insert into students (firstname,surname,year,form,gender) values(<dtml-sqlvar firstname type="string">, <dtml-sqlvar surname type="string">, <dtml-sqlvar year type="int">, <dtml-sqlvar form type="string">, <dtml-sqlvar gender type="string">) Now when i test this combination i get a missing input variable error: Missing input variable, firstname Can anyone see what I am missing? regards garry
garry saddington wrote:
Now i have an iterable file for the csv module in this code:
def students(self,REQUEST): import csv f=REQUEST.form["students.csv"] from cStringIO import StringIO filebody=StringIO(f.read()) reader = csv.DictReader(filebody,("firsname","surname", "year","form","gender")) for row in reader: self.writestudents(row)
Writestudents is a zsql method with the following body:
insert into students (firstname,surname,year,form,gender) values(<dtml-sqlvar firstname type="string">, <dtml-sqlvar surname type="string">, <dtml-sqlvar year type="int">, <dtml-sqlvar form type="string">, <dtml-sqlvar gender type="string">)
Now when i test this combination i get a missing input variable error:
Missing input variable, firstname
Can anyone see what I am missing?
If you copied-and-pasted the code, you have "firsname" instead of "firstname" in the "reader" line of "students". I would look at that first. --Jim Washington
On Sunday 08 August 2004 5:37 pm, Jim Washington wrote:
garry saddington wrote:
Now i have an iterable file for the csv module in this code:
def students(self,REQUEST): import csv f=REQUEST.form["students.csv"] from cStringIO import StringIO filebody=StringIO(f.read()) reader = csv.DictReader(filebody,("firsname","surname", "year","form","gender")) for row in reader: self.writestudents(row)
Writestudents is a zsql method with the following body:
insert into students (firstname,surname,year,form,gender) values(<dtml-sqlvar firstname type="string">, <dtml-sqlvar surname type="string">, <dtml-sqlvar year type="int">, <dtml-sqlvar form type="string">, <dtml-sqlvar gender type="string">)
Now when i test this combination i get a missing input variable error:
Missing input variable, firstname
Can anyone see what I am missing?
If you copied-and-pasted the code, you have "firsname" instead of "firstname" in the "reader" line of "students".
I would look at that first.
--Jim Washington
Thanks -what a dummy! I've got it working now. Thanks for all the help from this list it is an invaluable source of expertise. kind regards garry
garry saddington wrote at 2004-8-8 16:40 +0100:
... self.writestudents(row)
Writestudents is a zsql method with the following body:
Z SQL methods expect their parameters either as keyword parameters or in the REQUEST object. It has been written dozens of times... -- Dieter
Dieter Maurer wrote:
Z SQL methods expect their parameters either as keyword parameters or in the REQUEST object.
It has been written dozens of times...
Or as a single mapping object, according to the Z SQL method help. Are there any hidden complications to that? And can anybody give a simple example of using that format? I have been struggling with passing a record into a Z SQL method too. -- Les Ferguson Software developer Waitakere, NZ
* Les Ferguson <lhf@xtra.co.nz> [2004-08-09 10:39]:
Dieter Maurer wrote:
Z SQL methods expect their parameters either as keyword parameters or in the REQUEST object.
It has been written dozens of times...
Or as a single mapping object, according to the Z SQL method help.
Are there any hidden complications to that? And can anybody give a simple example of using that format?
I have been struggling with passing a record into a Z SQL method too.
If a ZSQL method has "one", "two" and "three" as arguments it can be called (a) with a single mapping object: d = {'one': 1, 'two': 2, 'three': 3'} some_zsql_method(d) NOTE: this is the same as calling the method with the REQUEST some_zsql_method(REQUEST) (b) or with keyword arguments: some_zsql_method(one=one, two=two, three=three) (c) or with no arguments in which case the method will try to acquire the values for all arguments: some_zsql_method() -- Roché Compaan Upfront Systems http://www.upfrontsystems.co.za
Thanx for that, it all looks quite simple really. Is it the same effect if I have a form with elements like: <input name="cstRec.Surname:record"> If the form posts to a python script, can I then pass cstRec to a ZSQL method, after validation etc ? Should Surname then be available as a dtml-sqlvar ? -- Les Ferguson Software developer Waitakere, NZ Roché Compaan wrote:
If a ZSQL method has "one", "two" and "three" as arguments it can be called (a) with a single mapping object:
d = {'one': 1, 'two': 2, 'three': 3'} some_zsql_method(d)
NOTE: this is the same as calling the method with the REQUEST
some_zsql_method(REQUEST)
(b) or with keyword arguments:
some_zsql_method(one=one, two=two, three=three)
(c) or with no arguments in which case the method will try to acquire the values for all arguments:
some_zsql_method()
Les Ferguson wrote at 2004-8-11 23:09 +1200:
Thanx for that, it all looks quite simple really. Is it the same effect if I have a form with elements like: <input name="cstRec.Surname:record">
If the form posts to a python script, can I then pass cstRec to a ZSQL method, after validation etc ?
Yes.
Should Surname then be available as a dtml-sqlvar ?
No. But inside a '<dtml-with "yourParameter">...</dtml-with>', it will be available: When you pass "cstRec", then "yourParamter" is a record and not a string... -- Dieter
How could I adapt this code to get a CSV file from a remote URI instead of the request?
Now i have an iterable file for the csv module in this code:
def students(self,REQUEST): import csv f=REQUEST.form["students.csv"] from cStringIO import StringIO filebody=StringIO(f.read()) reader = csv.DictReader(filebody,("firsname","surname", "year","form","gender")) for row in reader: self.writestudents(row)
TIA, -- David
participants (6)
-
David Siedband -
Dieter Maurer -
garry saddington -
Jim Washington -
Les Ferguson -
Roché Compaan