validators are originally written to work on FORMS, but web2py included an option to validate DAL inserts.
db.validate_and_insert(**values) & db.validate_and_update(**values) On Thu, Sep 22, 2011 at 7:33 AM, Chris Rowson <christopherrow...@gmail.com>wrote: > Quick question, > > If I put my validators in the model like this: > > db.data.speedtesturl.requires=IS_NOT_IN_DB(db, > 'data.speedtesturl',error_message='This speedtest URL is already in > the database. Please provide another') > > They only seem to work if I use SQLFORM. > > If I create a SQLFORM and then add an extra field to it like this: > > speedtesturl=TR(LABEL('Speedtest > URL'),INPUT(_name='speedtesturl',_type='text',)) > form[0].insert(-1,speedtesturl) > > and then add the data to the database a little later like this: > > db.data.insert(**dict(form.vars)) > > The validator doesn't validate the data from the extra field. > > To validate the data in the extra field I have to call the validator > in the controller like this: > > speedtesturl=TR(LABEL('Speedtest > URL'),INPUT(_name='speedtesturl',_type='text', > requires=IS_NOT_IN_DB(db, 'data.speedtesturl'))) > > Am I right in thinking then that validators written in the model only > work against data submitted using SQLFORM, and not against data > submitted in other ways? > > Thanks, > > Chris > -- -- Bruno Rocha [ About me: http://zerp.ly/rochacbruno ] [ Aprenda a programar: http://CursoDePython.com.br ] [ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ] [ Consultoria em desenvolvimento web: http://www.blouweb.com ]