>
> db.table('person',
> Field('company', 'integer', required = True),
> Field('photo_image', 'upload', required = True, requires = IS_IMAGE())
>
> def webservice_name():
> person_id = db.person.insert(company = request.vars.company_id,
> photo_image =
> db.person.image.store(request.vars.photo_image.file,
> request.vars.photo_image.filename))
>
> How would I call the validate_and_insert version of the above? I.e. invoke
> "validate" then "store" the image. (Couldn't seem to find any examples.)
>
You should probably just validate request.vars.photo_image before doing the
insert:
if db.person.photo_image.validate(request.vars.photo_image)[1] is None:
person_id = db.person.insert(company = request.vars.company_id,
photo_image =
db.person.image.store(request.vars.photo_image.file,request
.vars.photo_image.filename))
The validate() method of the field passes the value through all the fields
validators and returns a (value, error) tuple -- if the "error" component
of that tuple is None, that means it passed validation.
Anthony