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('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()
        csvtxt = csvtxt.replace('VERO', '1')
        csvtxt = csvtxt.replace('FALSO', '0')
        from cStringIO import StringIO
        print csvtxt
        db[table].import_from_csv_file(StringIO(csvtxt), delimiter=';')
    return locals()

View:

{{extend 'layout.html'}}
{{=form}}


With this, I was able to easily import the csv sample you provided.

-- 
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)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to