IN other words I want to do 

form.process(...).accepted in the for loop for no. of files uploaded.



On Thursday, July 2, 2015 at 12:26:09 PM UTC+5:30, Sujata Aghor wrote:
>
>
> My code( based on your mentioned solution) looks like this-
>
>             if form.accepts(request.vars):
>                 if hasattr(request.vars, 'txn_doc'):
>                     #if len(request.vars.txn_doc) > 0:
>                     files = request.vars['txn_doc']
>                     if not isinstance(files, list):
>                         files = [files]
>                    
>                     for f in files:
>                         print f.filename
>                         txn_doc = db.uploaded_docs.txn_doc.store(f, 
> f.filename)
>                         db.uploaded_docs.insert(
>                             
> portfolio_company=request.vars.portfolio_company,
>                             txn_area=request.vars.txn_area,
>                             document_name=request.vars.doc_name,
>                             txn_doc=f.filename,
>                            document_date=request.vars.document_date)
>                         db.commit()
>                         print "DEBUG: [%s] successfully uploaded" % 
> f.filename
>                     redirect(URL('upload', 'upload'))
>
>
> This is inserting +1 record to db. Not getting why it is so?
> Means if I upload 2 files it should insert 2 records in db; BUT it inserts 
> 3 (and the extra without file)
> Please help me!!!!
> On Thursday, January 9, 2014 at 1:05:44 AM UTC+5:30, Brando wrote:
>>
>> This works, added the requires statement for form validation:
>>
>> def submit():
>>     import datetime
>>     form = FORM(LABEL("File(s):"), INPUT(_name='up_files', _type='file', 
>> _multiple='', requires=IS_NOT_EMPTY()),  BR(),INPUT(_type='submit'))
>>     if form.accepts(request.vars, formname="form"):
>>         files = request.vars['up_files']
>>         if not isinstance(files, list):
>>             files = [files]
>>         for f in files:
>>             print f.filename
>>             up_file = db.uploads.up_file.store(f, f.filename)
>>             i = db.uploads.insert(notes=request.vars.notes, 
>> up_file=up_file, filename=f.filename, up_date= datetime.datetime.now())
>>             db.commit()
>>         return "form submitted" #redirect(URL('data', 'index'))
>>     return dict(form=form)
>>
>>
>>
>>

-- 
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.

Reply via email to