Let's isolate the problem.

Are you saying that even if you have this:

Field('up_file', 'upload', uploadseparate=True, requires =[IS_NOT_EMPTY(),
 IS_UPLOAD_FILENAME(extension=ext_regex)]),

You can submit a form that does not upload a file into up_file?

On Thursday, 26 December 2013 13:21:35 UTC-6, Calvin Morrison wrote:
>
> I'm following the documentation trying to figure out how to correctly save 
> a filename to my uploads database.
>
> Basically i have the same code as the website shows in it's examples
>
>
> def submit():
>
>
>  import datetime
>
>
>  form = SQLFORM(db.uploads, fields=['up_file', notes], deletable=True)
>
>
>  form.vars.up_date = datetime.datetime.now()
>  form.vars.username = auth.user.email
>
>
>  if request.vars.up_file != None:
>  form.vars.filename = request.vars.up_file.filename
>
>
>  if form.process().accepted:
>  redirect(URL('data', 'index'))
>  elif form.errors:
>  response.flash = "form has errors"
>
>
> But my form doesn't appear to be validating correctly. It allows me to hit 
> submit even if a file is not supplied. This leads to a error being logged, 
> so I want to avoid things getting submitted.  My only thought is that it 
> could be my requires not working correctly
>
> ext_regex = '|'.join(quikr_utils.all_ext)
>
> db.define_table('uploads',
>     Field('username', 'string'),
>     Field('filename', represent = lambda x, row: "None" if x == None elsex
> [:45]),
>     Field('up_file', 'upload', uploadseparate=True, requires=[IS_NOT_EMPTY
> (), IS_UPLOAD_FILENAME(extension=ext_regex)]),
>     Field('up_date', 'datetime'), 
>     Field('up_size', 'integer', represent= lambda x, row: quikr_utils.
> sizeof_fmt(x) ), 
>     Field('notes', 'text'))
>
> >>> print quikr_utils.all_ext
> ['fasta','fa','fna','fasta.gz','fa.gz','fna.gz']
>
> Any ideas?
> Thanks!
>

-- 
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/groups/opt_out.

Reply via email to