upload field and IS_IMAGE

35 views
Skip to first unread message

Kirill Shatalaev

unread,
Aug 18, 2016, 5:38:54 PM8/18/16
to web...@googlegroups.com
Hello.

I have in model:

Field('avatar', 'upload', required=False, autodelete=True, label=T('Avatar'),
uploadfolder=os.path.join(request.folder, 'static/images/avatars'),
requires=[IS_LENGTH(16384), IS_IMAGE()])

Well, the logic is simple: "avatar is not necessary, but when it uploaded, it must be image size of <= 16KiB".

But I can not submit form without image uploading, error is "Invalid Image" always. I can submit form only if image of proper size.

When I remove IS_IMAGE() check, it works as expected - I can submit form without file, or with file size of 16KiB max.

Is it a bug or I do not understand something?

黄祥

unread,
Aug 18, 2016, 7:48:12 PM8/18/16
to web2py-users
pls try :
requires = IS_EMPTY_OR([IS_LENGTH(16384), IS_IMAGE() ] )

best regards,
stifan

Kirill Shatalaev

unread,
Aug 19, 2016, 8:41:55 AM8/19/16
to web2py-users


пятница, 19 августа 2016 г., 3:48:12 UTC+4 пользователь 黄祥 написал:
Man, thanks!!! I completely forgot about this validator. Need to sleep more...
Reply all
Reply to author
Forward
0 new messages