Hi William,

I'm definitely a fan of DRY, but I'd like to hold off on this change
for now. As part of the CRUD work, a mechanism that will have the same
end result may very well come into existence.

One of the reasons I didn't head down this path before is that
validation/conversion coming from the web may be a different thing
than conversion heading into SQLObject. The notion of a
default_validators option does allow for overriding this, which is
good. But, as I said, this may have a differently shaped but equally
good solution come up.

Kevin

On 11/12/05, william <[EMAIL PROTECTED]> wrote:
>
> 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
>
>


--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Reply via email to