On Jan 26, 5:33 am, eleith <[email protected]> wrote:
> for my schema, i want to handle
> ----------------------------------------
> delete?id=100
> delete?id=100&id=101&id=102
>
> and throw an error for
>
> delete?
> -----------------------------------------
> my validators look like this:
>
> id = ForEach(Int(), not_empty=True, convert_to_list=True)
>
> however, this passes when even when i don't pass in an 'id'
>
> i've even tried
>
> All(NotEmpty(), ForEach(....))
>
> that doesn't work either. i've ended up writing my own function and
> subclassing into SimpleFormValidator to handle this case for me (i
> just check if the len(values['id']) < 1, and return an error message)
>
> so either i'm going about this the wrong way, or there is an error in
> ForEach and/or All.
>
> any suggestions? (although, i'm happy with my solution, just thought i
> would publish my findings)
I've had similar issues in the past that I dealt with like this, not
sure if this is what you're looking for or not.
import formencode as fe
class IdValidator(fe.FancyValidator):
def _to_python(self, value, state):
ret = {'id':[]}
for v in value:
try:
ret['id'].append(int(v))
except (ValueError, TypeError):
raise fe.Invalid('id must be integer',
value, state)
return ret
class InputFormSchema(fe.Schema):
allow_extra_fields = True
filter_extra_fields = True
id = IdValidator()
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---