It works great. Thanks !!

On Friday, June 1, 2012 2:56:58 PM UTC-5, Anthony wrote:
>
> if hasattr(request.vars.csvfile, 'file'):
>
> Anthony
>
> On Friday, June 1, 2012 3:51:09 PM UTC-4, Omi Chiba wrote:
>>
>> I have a simple upload form. It works fine but it shows the following 
>> error when user submit it without selecting file. How can I check 
>> if request.vars.csvfile.file attribute exists ?
>>
>>  File "C:/trunk/web2py/applications/tedi/controllers/default.py", line 
>> 110, in customer_upload
>>     if request.vars.csvfile != None:
>> AttributeError: 'str' object has no attribute 'file'
>>
>> *view*
>> {{extend 'layout.html'}}
>>
>> {{=FORM(INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value='EDXTKF00',_name='table'),INPUT(_type='submit',_class='btn',_value='Upload'))}}
>>
>> *controller*
>> def customer_upload():
>>     response.title = 'Upload'
>>     response.subtitle = 'Customer Code'
>>     
>>     if request.vars.csvfile != None: 
>>        # set values
>>        table = db[request.vars.table]
>>        file = request.vars.csvfile.file
>>         
>>        # import csv file
>>        table.import_from_csv_file(file)
>>         
>>        # update who imported
>>        query = db.EDXTKF00.TKUPFL==""
>>        db(query).update(TKUPFL="1")
>>         
>>        session.flash = 'Data Uploaded'
>>        redirect(URL('customer_index'))
>>     
>>     return dict()
>>
>>
>>
On Friday, June 1, 2012 2:56:58 PM UTC-5, Anthony wrote:
>
> if hasattr(request.vars.csvfile, 'file'):
>
> Anthony
>
> On Friday, June 1, 2012 3:51:09 PM UTC-4, Omi Chiba wrote:
>>
>> I have a simple upload form. It works fine but it shows the following 
>> error when user submit it without selecting file. How can I check 
>> if request.vars.csvfile.file attribute exists ?
>>
>>  File "C:/trunk/web2py/applications/tedi/controllers/default.py", line 
>> 110, in customer_upload
>>     if request.vars.csvfile != None:
>> AttributeError: 'str' object has no attribute 'file'
>>
>> *view*
>> {{extend 'layout.html'}}
>>
>> {{=FORM(INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value='EDXTKF00',_name='table'),INPUT(_type='submit',_class='btn',_value='Upload'))}}
>>
>> *controller*
>> def customer_upload():
>>     response.title = 'Upload'
>>     response.subtitle = 'Customer Code'
>>     
>>     if request.vars.csvfile != None: 
>>        # set values
>>        table = db[request.vars.table]
>>        file = request.vars.csvfile.file
>>         
>>        # import csv file
>>        table.import_from_csv_file(file)
>>         
>>        # update who imported
>>        query = db.EDXTKF00.TKUPFL==""
>>        db(query).update(TKUPFL="1")
>>         
>>        session.flash = 'Data Uploaded'
>>        redirect(URL('customer_index'))
>>     
>>     return dict()
>>
>>
>>

Reply via email to