[web2py] Re: save upload filename in database

2013-12-27 Thread Massimo Di Pierro
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.


[web2py] Re: save upload filename in database

2013-12-28 Thread Calvin Morrison
More specifically this only happens if I put in the if up_name != None 
check to set the filename in the database, otherwise it works well

On Friday, December 27, 2013 11:48:09 PM UTC-5, Massimo Di Pierro wrote:
>
> 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.


Re: [web2py] Re: save upload filename in database

2013-12-28 Thread Calvin Morrison
Yes that's exactly the problem!

Which in turn causes the other problems I think
On Dec 27, 2013 11:48 PM, "Massimo Di Pierro" 
wrote:

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

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


Re: [web2py] Re: save upload filename in database

2013-12-31 Thread Calvin Morrison
Here is my solution!


  if hasattr(request.vars['up_file'],"filename"):
form.vars.filename = request.vars['up_file'].filename

  if form.process().accepted:
redirect(URL('data', 'index'))
  elif form.errors:
response.flash = "form has errors"

On 28 December 2013 17:08, Calvin Morrison  wrote:
> More specifically this only happens if I put in the if up_name != None check
> to set the filename in the database, otherwise it works well
>
>
> On Friday, December 27, 2013 11:48:09 PM UTC-5, Massimo Di Pierro wrote:
>>
>> 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 else
>>> x[: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.

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