Hi all!
I'm starting to use pyramid with deform library(migarting from
pylons-1.0).
Colander library has a built-in validator OneOf to check a single
value against the predefined list of allowed values. But I can't find
something like Formencode OneOf with testValuesList=True validator.
I think it's a common case to use multiselect widget where you can
select several
values from the predefined list.
It's simple to implement one, just like this:
class SubsetValidator(object):
def __init__(self, choices):
self.choices = choices
def __call__(self, node, value):
for v in value:
if v not in self.choices:
choices = ', '.join(['%s' % x for x in self.choices])
err = _('"${val}" is not one of ${choices}',
mapping={'val':value, 'choices':choices})
raise Invalid(node, err)
But it will be cool to get Subset validator out of the box.
--
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.