I tried to import a CSV file but all the values are None.
This is what I did:
def index():
if request.vars.csvfile != None:
table = db[request.vars.table]
file = request.vars.csvfile.file
table.import_from_csv_file(file)
return dict()
My tables look like this:
db.define_table('animation',
Field('activity', widget=SQLFORM.widgets.radio.widget,
requires=IS_IN_SET({'Co-prod', 'Buyer','Sales', 'Producer', 'Director'})),
Field('business', widget=SQLFORM.widgets.radio.widget,
requires=IS_IN_SET({'Distribution', 'Broadcaster','Production', 'Internet',
'Financing', 'MNO', 'Press'})), Field('company', 'string',
requires=[IS_NOT_EMPTY()]), Field('country', requires=[IS_NOT_EMPTY()]),
Field('email', requires=[IS_NOT_EMPTY(), IS_EMAIL()]), Field('first_name',
'string',requires=IS_NOT_EMPTY()), Field('last_name',
'string',requires=IS_NOT_EMPTY()), Field('position_title',
'string',requires=IS_NOT_EMPTY()), Field('website',
'string',requires=[IS_NOT_EMPTY(), IS_URL]), Field('date_made', 'datetime',
default = request.now, writable=False, readable=False, requires =
IS_DATE(format=('%d-%m-%Y'))))
My view:
{{extend 'layout.html'}}
{{=FORM(INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value='animation',_name='table'),INPUT(_type='submit',_value='Upload'))}}
The CSV file has the same headers as the table names. The CSV is imported,
the length of the rows in the database are the same as in the CSV file but
the records are all None.
What I want to do is to be able to import CSV files to this db as well as
input values manually using a form. This is why I am using a radio.widget.
What am I doing wrong?
Thanks.
Joe
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.