Re: Partial validation results from an invalid input?

Daniel Lepage <[email protected]> Mon, 26 Dec 2011 17:55:42 -0500
Newsgroups gmane.comp.python.formencode
Message-ID <CANtoCQ8Srr5+FJ0KPYPcdno8HHwUWzVB5c3HosK4-D2ttUs_nQ@mail.gmail.com>
Hi Chris,

I have a web form that can be edited and saved multiple times. When
the user inputs data, all valid fields are saved and all invalid
fields display error messages.

So I need to show the error messages for the invalid fields AND get
the python values of the valid fields.

Right now my hack is a subclass of Schema that overrides _to_python
with a function that is char-for-char identical except for a single
line, where instead of raising Invalid I raise a custom subclass
(PartialInvalid) that also contains all the valid values.

This works well enough, but it's inelegant, so I was hoping to find a
better solution.

Thanks,
Dan

On Mon, Dec 26, 2011 at 5:41 PM, Chris Lambacher <[email protected]> wrote:
> Hi Dan,
>
> There is no official and nice way of doing that and without knowing
> why you want to do that I would guess "you are doing it wrong". There
> are some hackish ways that you might be able to get the value but they
> are likely to be error prone.
>
> Can you elaborate on why you want to do it that way? Do you want to
> display the error? Do you want to ignore the error?
>
> -Chris
>
>
> On Mon, Dec 26, 2011 at 5:12 PM, Daniel Lepage <[email protected]> wrote:
>> Hi everyone,
>>
>> Is there a way to get the python values for successful fields in a
>> Schema when other fields have failed?
>>
>> For example, suppose I have the following schema and input value:
>>
>> sch = Schema(fields=dict(x=Int(), y=DateConverter(), z=Int()))
>> v = dict(x='12', y='1/16/1973', z='foo')
>>
>> I'd like to validate v against sch in such a way that I get not only
>> the error message from z, but also the values 12 and datetime(1973, 1,
>> 16) from x and y, respectively.
>>
>> Is there a way to do this?
>>
>> None of my use cases rely on chained_validators, so all I need are the
>> values computed by the fields of the schema.
>>
>> Thanks,
>> Dan Lepage
>>
>> ------------------------------------------------------------------------------
>> Write once. Port to many.
>> Get the SDK and tools to simplify cross-platform app development. Create
>> new or port existing apps to sell to consumers worldwide. Explore the
>> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
>> http://p.sf.net/sfu/intel-appdev
>> _______________________________________________
>> FormEncode-discuss mailing list
>> FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>> https://lists.sourceforge.net/lists/listinfo/formencode-discuss
>
>
>
> --
> Christopher Lambacher
> [email protected]

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev