I've got a solution:
The idea is to simply give the model objects to "default_validators". A
new parameter of expose decorator.
The modified decorator will grab the validator use in SQLObject and
apply it to all fields that he receive.
Thus, if you have a big table (called Mesures in my example) with lot
of Integer (for example), just do:
@turbogears.expose(default_validators=[Mesures])
def save(self,**kw):
....
All values defined as integer in model.Mesures will automatically be
transformed.
That will allow you to do something like:
m=Mesures(**kw)
if you want to add a new record
default_validators is a list. Thus is you form is a mix of 2 tables,
you can give 2.
Problems will still occurs if the 2 table have 2 fields with the same
name but different validator.
I've tested it with my Mesures table (lot of integer) and it works.
I've not yet test it fully.
I like it because it's simplier, but actually I don't know if it's a
good idea.
But it fit my needs ;-).
Patch based on rev_164 of controllers.py
99c99
< def expose(html=None, validators=None, default_validators=None,
allow_json=None,
---
> def expose(html=None, validators=None, allow_json=None,
180,191d179
< #default validator
< if default_validators:
< coldef={}
< for obj in default_validators:
< for col in obj.sqlmeta.columnList:
< coldef[col.name]=col.validator
< for field in kw:
< if field in coldef:
< try:
<
kw[field]=coldef[field].to_python(kw[field],None)
< except turbogearsvalid.Invalid, error:
< errors[field] = error