I tried to import a CSV file but all the values are None.
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()
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'))))
{{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.
Thanks.