You can use an if-else or try-except block for that
Like this.
def index():
form = SQLFORM(db.orders)
if form.process().accepted:
if form.vars.pic_upload:
makeThumbnail(db.orders,form.vars.id,(175,175))
else:
#do whatever you want
else:
response.flash = 'form has errors'
return locals()
Hope this helps you.
Thanks
SP
On Fri, Jan 11, 2019 at 5:32 PM Arindam Dasgupta <[email protected]>
wrote:
> Hi,
>
> I have a problem with checking whether the file upload field in the
> database is empty or not.
> In the code mentioned below, the user can either upload a file or submit
> the form without uploading a file.
> If the user uploads a file then the " makeThumbnail" function should be
> called. Otherwise it shouldn't be called.
> The statement like if db.orders.pic_upload !="": is not working. What
> is the right way of achieve this ? Thanks in advance!!
>
> My Model
> ------------------------
> db.define_table('orders',
> Field('item_type' ,type='string',default='--'),
>
> Field('pic_upload' ,'upload',autodelete=True),
>
> Field('thumb','upload',writable=False,readable=False,autodelete=True),
>
> auth.signature
> )
>
>
> My Controller
> --------------------------
> form = SQLFORM(db.orders)
>
> if form.process().accepted:
>
> if db.orders.pic_upload !="":
> makeThumbnail(db.orders,form.vars.id,(175,175))
> else:
> response.flash = 'form has errors'
>
>
>
>
> Best Regards,
> Arindam
>
> --
> 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.
>
--
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.