Discussion:
[FE-discuss] a question for anyone using formencode and pylons/pyramid ...
Chris Lambacher
2012-02-23 02:07:03 UTC
Permalink
Hi Vanasco,

This is a generic FormEncode question so you should ask on the FormEncode
list. I copied that list on this email. The FormEncode list is pretty low
volume, but the maintainers do respond ;).

You might want to include what you want as your final state (for instance I
assume you want ints rather than unicode values).

You could then use a Pipe validator:

from formencode import Pipe
from formencode.validators import OneOf, Int

account_type_ids= (1,2,3,4,5)

#must be one of the items in account_type_ids
validator = Pipe(Int(),OneOf(account_ type_ids)

#must be int between 1 and 5
validator = Int(min=1, max=5)

Note that if account_type_ids is not *actually* a list or tuple there may
be other options including DictConverter.

Some useful doc links:
http://www.formencode.org/en/latest/modules/compound.html#formencode.compound.Pipe

http://www.formencode.org/en/latest/modules/validators.html#formencode.validators.Int
http://www.formencode.org/en/latest/modules/validators.html#formencode.validators.DictConverter


-Chris
the request get/post data comes in from pyramid as unicode strings.
the values i have in the database / my code for constant on many items
are integers
let's use this as an example...
account_type_ids= (1,2,3,4,5)
other_type_ids= (1,2,3,4,5)
third_type_ids= (1,2,3,4,5)
return [ u"%s" % i for i in listed ]
account_type_id =
formencode.validators.OneOf( unicode_wrap(account_type_ids),
not_empty=True )
other_type_id =
formencode.validators.OneOf( unicode_wrap(other_type_ids),
not_empty=True )
third_type_id =
formencode.validators.OneOf( unicode_wrap(third_type_ids),
not_empty=True )
i've combed the formencode docs and list archives, but just I can't
figure out a good way to handle this.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.
Loading...