[web2py] Re: Replacing characters in a csv file from request.vars

2014-10-05 Thread Gael Princivalle
Shame on me. I've wrote cvstxt instead of csvtxt... Anyway you've teach me some tricks, thanks a lot. Il giorno domenica 5 ottobre 2014 12:41:24 UTC+2, Leonel Câmara ha scritto: > > This worked for me: > > Model: > > db.define_table('products', > Field('id_crm', 'integer'), > Field('code'

[web2py] Re: Replacing characters in a csv file from request.vars

2014-10-05 Thread Leonel Câmara
This worked for me: Model: db.define_table('products', Field('id_crm', 'integer'), Field('code'), Field('description', 'text'), Field('price_list', 'decimal(10,5)'), Field('special_offer', 'boolean'), ) Controller: def from_csv(): form = SQLFORM.factory( Field('t

Re: [web2py] Re: Replacing characters in a csv file from request.vars

2014-10-04 Thread Gael Princivalle
Thanks Leonel. Here is my form: form = SQLFORM.factory( Field('table',requires=IS_IN_SET(db.tables)), Field('csvfile','upload',uploadfield=False)) form.process() if form.accepted: table = form.vars.table csvtxt = request.vars.csvfile.file.read()

[web2py] Re: Replacing characters in a csv file from request.vars

2014-10-03 Thread Leonel Câmara
No, what I mean is, can I see the form you use to upload. And can you show me more of that controller and/or more of the ticket error. The error you're getting "global name 'cvsfile' is not defined" doesn't make sense to me. An alternative is to read the excel directly using xlrd ( http://www.

[web2py] Re: Replacing characters in a csv file from request.vars

2014-10-03 Thread Gael Princivalle
I'm creating the csv file like that. >From a CRM I export data in the only format available, Excel. >From Excel I export in CSV. After that I have to replace a lot of things inside the file. First "," with "." for decimal separator. ";" with "," for field separator "FALSO" with "0" "VERO" with "1"

[web2py] Re: Replacing characters in a csv file from request.vars

2014-10-03 Thread Leonel Câmara
How are you creating your csv file input? Along with delimiter you can also change quotechar and quoting. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) ---

Re: [web2py] Re: Replacing characters in a csv file from request.vars

2014-10-03 Thread Gael Princivalle
Thanks Leonel No it don't. >However, this is not necessary as you can send the delimiter to import_from_csv_file. So this may be enough: >db.products.import_from_csv_file(request.vars.csvfile.file, delimiter=';') Great but I need to replace other characters. -- Gael Princiva

[web2py] Re: Replacing characters in a csv file from request.vars

2014-10-03 Thread Leonel Câmara
Does this work? csvtxt = request.vars.csvfile.file.read() csvtxt = csvtxt.replace(';', ',') from cStringIO import StringIO db.products.import_from_csv_file(StringIO(csvtxt)) However, this is not necessary as you can send the delimiter to import_from_csv_file. So this may be enough: db.products.