On Friday, July 8, 2016 at 8:51:21 PM UTC-4, Alfonso Serra wrote: > > Sorry, to finish up some considerations... > > Ive been investigating how web2py assigns default validators (or widgets) > to field types. > > If im not wrong this is done by SQLFORM which imports a function from > gluon.dal called _default_validators. >
Actually, pydal (independent of web2py) includes two ways of specifying default validators based on field type -- the DAL has class attributes "validator_method" and "validators". The first is a function that takes a DAL instance and a Field and returns a validator, and the second is a dictionary mapping field types to validators. The gluon.dal module is part of web2py, and it sets the DAL.validator_method function to _default_validators, but you are free to override that, or use the DAL.validators dictionary as an alternative (you would first have to delete DAL.validator_method, as it takes precedence over DAL.validators). > Its a shame that these relationships cannot be extended since it looks > like creating a new field type, is as easy as something like: > db._adapter.types['booleantri']='TINYINT(1)' > > Actually, the API for creating a custom field type is http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Custom-Field-types--experimental-. Note, it isn't documented, but SQLCustomType also takes "validator", "represent", "widget", and "_class" arguments, so you can specify defaults for all of those attributes as well (i.e., no need to bother with DAL.validator_method or _default_validators). Anthony -- 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/d/optout.