Re: Chained validators and error messages

Ian Bicking <[email protected]> Wed, 4 Mar 2009 21:48:38 -0600
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
On Wed, Mar 4, 2009 at 3:57 AM, Andrea Riciputi <[email protected]> wrote:
> I'm trying to make htmlfill to put the error message raised by a
> chained validator near a specific form field.
>
> To get this I've written a custom validator where the messages dict is
> defined like this:
>
> messages = {'my_error_label': u"Error message goes here" }
>
> then, if the conditions are not met I raise the Invalid exception like
> this:
>
> raise Invalid(self.message('my_error_label', state),
> values, state,
> error_dict={
> 'my_error_label': Invalid(self.message('field_name', state), values,
> state)
> })
>
> Despite the fact this gives me the expected result, I'm not sure I'm
> raising that exception in the correct way. I mean, I got the
> impression that the Invalid instance could be called in easier way,
> but I really can't see how. Any suggestion?

Yeah, that's right -- it's a little awkward, but usually this
particular kind of exception is only raised in Schema, so people don't
see the awkwardness as much ;)



-- 
Ian Bicking  |  http://blog.ianbicking.org

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H