Re: Problems with Formencode Msgs, Unexpected Inputs
Ian Bicking <[email protected]> Fri, 03 Oct 2008 13:41:30 -0500
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Tom Longson (nym) wrote:
> Hi,
>
> I'm trying to get formencode to work, and I have a few problems:
>
> 1. How do you supply custom error messages? I've read the documentation,
> and couldn't find a concrete example using preexisting validators.
Each validator has a list of messages, which you can see in the docs.
For instance, Regex(r'^\w+$', messages={'invalid': 'Please enter just
letters and numbers'}).
> 2. Why am i getting this error list with the included test file?
>
> List of dictionaries:
> [{'name': 'Tom'}, {'email':
> 'tom-1ejvVKqOCHmevrI51Aqiyd1ocvOgFGy0LpsAlfeDtJ10ubjbjo6WXg@public.gmane.org
> <mailto:tom-1ejvVKqOCHmevrI51Aqiyd1ocvOgFGy0LpsAlfeDtJ10ubjbjo6WXg@public.gmane.org>'}, {'password':
> 'narfffff0'}, {'password_confirm': 'narfffff0'}]
>
> Error list:
> [Invalid('email: Missing value\npassword: Missing
> value\npassword_confirm: Missing value',), Invalid('name: Missing
> value\npassword: Missing value\npassword_confirm: Missing value',),
> Invalid('email: Missing value\nname: Missing
> value\npassword_confirm: Missing value',), Invalid('email: Missing
> value\nname: Missing value\npassword: Missing value',)]
You get a single exception for invalid input, that contains all the
exceptions for the individual fields. Probably you'll find it easiest
to use exc.unpack_errors() to get a list of messages.
> 3. If I supply a value to the list of dictionaries that is not expected
> by the Schema (e.g. "foobar"), how do I get the Schema to ignore it
> instead of throwing an Invalid(u"The input field '%s' was not expected.",) ?
on the schema, filter_extra_fields=True.
--
Ian Bicking : [email protected] : http://blog.ianbicking.org
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/