Re: Allowing validation to pass for partial post values?

Chris Lambacher <[email protected]> Fri, 27 Jul 2012 16:04:17 -0400
Newsgroups gmane.comp.python.formencode
Message-ID <CAAXXHg+cHurpoa+ZyK2AFZ9+LHp2Xm01EpYuXw3oQozfO_dyhg@mail.gmail.com>
--===============7930400046693633785==
Content-Type: multipart/alternative; boundary=20cf307abdf5914e2604c5d5377b

--20cf307abdf5914e2604c5d5377b
Content-Type: text/plain; charset=UTF-8

Hi Iain,

If what you want is to do is conditionally require some values then what
you are looking for is RequireIfMissing/RequireIfPresent which you put in
the chained_validators for the Schema:
http://www.formencode.org/en/latest/modules/validators.html#formencode.validators.RequireIfMissing


Note that it won't block other validation errors, so if you have an Int
validator and get a string, that validator will still give you an error
even if it will ultimately be ignored.

If that is a concern you can do a pre_validator that modifies / replaces
the value dict such that it includes only the values that should be kept.

-Chris

On Fri, Jul 27, 2012 at 2:39 PM, Iain Duncan <[email protected]>wrote:

> Hi, I'm using form encode for validation, and am building a ReST back end
> for use with Dojo data stores. the Dojo system wants to be able to use PUT
> requests with partial lists of params, and I'm trying to figure out best to
> do that. So if I have a schema, and some keys are missing, I want it to
> 'pass', with the values dictionary as is, rather than having the values
> dict have values for the missing keys that come from using if_missing='foo'.
>
> Is there way to do that without resorting to hackery like inspecting the
> errors and discarding all the ones that are missing value errors?
>
> thanks
> Iain
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> FormEncode-discuss mailing list
> FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/formencode-discuss
>
>


-- 
Christopher Lambacher
[email protected]

--20cf307abdf5914e2604c5d5377b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div>Hi=C2=A0Iain,</div><div><br></div>If what you want is to do is conditi=
onally require some values then what you are looking for is RequireIfMissin=
g/RequireIfPresent which you put in the chained_validators for the Schema:<=
div>
<a href=3D"http://www.formencode.org/en/latest/modules/validators.html#form=
encode.validators.RequireIfMissing">http://www.formencode.org/en/latest/mod=
ules/validators.html#formencode.validators.RequireIfMissing</a>=C2=A0</div>=
<div>
<br></div><div>Note that it won&#39;t block other validation errors, so if =
you have an Int validator and get a string, that validator will still give =
you an error even if it will ultimately be ignored.</div><div><br></div>
<div>If that is a concern you can do a pre_validator that modifies / replac=
es the value dict such that it includes only the values that should be kept=
.</div><div><br></div><div>-Chris<br><br><div class=3D"gmail_quote">On Fri,=
 Jul 27, 2012 at 2:39 PM, Iain Duncan <span dir=3D"ltr">&lt;<a href=3D"mail=
to:[email protected]" target=3D"_blank">[email protected]</=
a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi, I&#39;m using form encode for validation=
, and am building a ReST back end for use with Dojo data stores. the Dojo s=
ystem wants to be able to use PUT requests with partial lists of params, an=
d I&#39;m trying to figure out best to do that. So if I have a schema, and =
some keys are missing, I want it to &#39;pass&#39;, with the values diction=
ary as is, rather than having the values dict have values for the missing k=
eys that come from using if_missing=3D&#39;foo&#39;.<div>

<br></div><div>Is there way to do that without resorting to hackery like in=
specting the errors and discarding all the ones that are missing value erro=
rs?</div><div><br></div><div>thanks</div><span class=3D"HOEnZb"><font color=
=3D"#888888"><div>
Iain</div>
</font></span><br>---------------------------------------------------------=
---------------------<br>
Live Security Virtual Conference<br>
Exclusive live event will cover all the ways today&#39;s security and<br>
threat landscape has changed and how IT managers can respond. Discussions<b=
r>
will include endpoint security, mobile security and the latest in malware<b=
r>
threats. <a href=3D"http://www.accelacomm.com/jaw/sfrnl04242012/114/5012226=
3/" target=3D"_blank">http://www.accelacomm.com/jaw/sfrnl04242012/114/50122=
263/</a><br>_______________________________________________<br>
FormEncode-discuss mailing list<br>
<a href=3D"mailto:FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org">FormEncode-disc=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/formencode-discuss"=
 target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/formencode-=
discuss</a><br>
<br></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>Christop=
her Lambacher<br><a href=3D"mailto:[email protected]">chris@kateandchr=
is.net</a><br>
</div>

--20cf307abdf5914e2604c5d5377b--


--===============7930400046693633785==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
--===============7930400046693633785==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/formencode-discuss

--===============7930400046693633785==--