Just an additional note, you can combine validators to solve the int/
str problem using All or Any, (from formencode import All, Any) such
as:

my_select = All(OneOf([0,1,2,3,5,8,13,21,34]), Int())

So here Int converts the string to an integer and that integer gets
checked by OneOf.
You probably noticed that All actually works backwards, which I think
maybe is a long standing bug.

On Mar 2, 10:57 pm, Jonathan Vanasco <[email protected]> wrote:
> sorry, i'm sick and really loopy...
>
> let me rephrase ( and this may have changed since last i tested a
> while bac )
>
> everything that comes through request.params / submitted to your
> pylons app is a string
>
> there are some neat validators that will handle conversions for you,
> so everything is seamless / painless
>
> however, lets say that your select field has only these valid ids,
> which you know of as constants from your database:
>
>     valid_ids= [0,1,2,3,5,8,13,21,34]
>
> but if you choose something like:
>    valid= formencode.validators.OneOf( valid_ids )
>
> most will be invalid , because this is really what we want:
>    valid= formencode.validators.OneOf( [ "%s"%i for i in valid_ids] )
>
> so...
>
> enter things like mike's neat validator, which is """A combination of
> the Int and OneOf validators with a custom message"""
>
> and now you're able to do
>    valid= formencode.validators.SelectInt( valid_ids )

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to