Re: Allowing validation to pass for partial post values?
Chris Lambacher <[email protected]> Fri, 27 Jul 2012 16:32:34 -0400
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <CAAXXHgJTRdk7Z+KWwcZ-tcBwTRexhUOpB6wJ+-XtJJHTdg=PNw@mail.gmail.com> |
--===============2631463205679511010== Content-Type: multipart/alternative; boundary=14dae9cfcd16abb25904c5d59c78 --14dae9cfcd16abb25904c5d59c78 Content-Type: text/plain; charset=UTF-8 On Fri, Jul 27, 2012 at 4:17 PM, Iain Duncan <[email protected]> > > This should pass: > { 'name_last':'Duncan', 'birthdate':'1911-01-01'} > > This should fail: > {'name_last':'Duncan', 'name_first': '', 'birthdate': '1911-01-01' } > > thanks! > I don't think I am totally clear on the problem yet, but I am guessing that you don't like the Value Missing error in the first case and the second case the Empty value error is correct. If that is correct then what you want I think is: class PersonValidationSchema(ValidationSchema): """validation schema for resource Person""" # will take if_missing value unvalidated name_first = v.UnicodeString(not_empty=True, if_missing=None) name_last = v.UnicodeString(not_empty=True, if_missing=None) birthdate = IsoDate() or class PersonValidationSchema(ValidationSchema): """validation schema for resource Person""" # will totally ignore a missing value (unless if_missing provided) ignore_key_missing = True name_first = v.UnicodeString(not_empty=True) name_last = v.UnicodeString(not_empty=True) birthdate = IsoDate() or class PersonValidationSchema(ValidationSchema): """validation schema for resource Person""" # will run the validator with the value given (i.e. None) if_key_missing = None name_first = v.UnicodeString(not_empty=True) name_last = v.UnicodeString(not_empty=True) birthdate = IsoDate() -Chris -- Christopher Lambacher [email protected] --14dae9cfcd16abb25904c5d59c78 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Fri, Jul 27, 2012 at 4:17 PM, Iain Duncan <sp= an dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_= blank">[email protected]</a>></span>=C2=A0<blockquote class=3D"g= mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l= eft:1ex"> <div class=3D"gmail_quote"><div>This should pass:</div><div>{ 'name_las= t':'Duncan', 'birthdate':'1911-01-01'}</div><di= v><br></div><div>This should fail:</div><div>{'name_last':'Dunc= an', 'name_first': '', 'birthdate': '1911-0= 1-01' }</div> <div><br></div><div>thanks!</div></div> </blockquote></div><div><br></div>I don't think I am totally clear on t= he problem yet, but I am guessing that you don't like the Value Missing= error in the first case and the second case the Empty value error is corre= ct. If that is correct then what you want I think is:<div> <br><div style=3D"color:rgb(34,34,34);font-family:arial,sans-serif;font-siz= e:13px;background-color:rgb(255,255,255)">class PersonValidationSchema(Vali= dationSchema):</div><div style=3D"color:rgb(34,34,34);font-family:arial,san= s-serif;font-size:13px;background-color:rgb(255,255,255)"> =C2=A0 =C2=A0 """validation schema for resource Person"= ""</div><div style=3D"color:rgb(34,34,34);font-family:arial,sans-= serif;font-size:13px;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 # wil= l take if_missing value unvalidated</div> <div style=3D"color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13= px;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 name_first =3D v.Unicod= eString(not_empty=3DTrue, if_missing=3DNone)</div><div style=3D"color:rgb(3= 4,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(2= 55,255,255)"> =C2=A0 =C2=A0 name_last =3D v.UnicodeString(not_empty=3DTrue, if_missing=3D= None)</div><div style=3D"color:rgb(34,34,34);font-family:arial,sans-serif;f= ont-size:13px;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 birthdate = =3D IsoDate()</div><div><br> </div><div>or=C2=A0</div><div><br></div><div><div style=3D"font-size:13px;c= olor:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,25= 5,255)">class PersonValidationSchema(ValidationSchema):</div><div style=3D"= font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-= color:rgb(255,255,255)"> =C2=A0 =C2=A0 """validation schema for resource Person"= ""</div><div style=3D"font-size:13px;color:rgb(34,34,34);font-fam= ily:arial,sans-serif;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 # wil= l totally ignore a missing value (unless if_missing provided)</div> <div style=3D"font-size:13px;color:rgb(34,34,34);font-family:arial,sans-ser= if;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 ignore_key_missing =3D = True=C2=A0</div><div style=3D"font-size:13px;color:rgb(34,34,34);font-famil= y:arial,sans-serif;background-color:rgb(255,255,255)"> =C2=A0 =C2=A0 name_first =3D v.UnicodeString(not_empty=3DTrue)</div><div st= yle=3D"font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;back= ground-color:rgb(255,255,255)">=C2=A0 =C2=A0 name_last =3D v.UnicodeString(= not_empty=3DTrue)</div><div style=3D"font-size:13px;color:rgb(34,34,34);fon= t-family:arial,sans-serif;background-color:rgb(255,255,255)"> =C2=A0 =C2=A0 birthdate =3D IsoDate()</div><br class=3D"Apple-interchange-n= ewline"></div><div>or=C2=A0</div><div><br></div><div><div style=3D"font-siz= e:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rg= b(255,255,255)">class PersonValidationSchema(ValidationSchema):</div> <div style=3D"font-size:13px;color:rgb(34,34,34);font-family:arial,sans-ser= if;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 """valid= ation schema for resource Person"""</div><div style=3D"font-= size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color= :rgb(255,255,255)"> =C2=A0 =C2=A0 # will run the validator with the value given (i.e. None)</di= v><div style=3D"font-size:13px;color:rgb(34,34,34);font-family:arial,sans-s= erif;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 if_key_missing =3D No= ne</div><div style=3D"font-size:13px;color:rgb(34,34,34);font-family:arial,= sans-serif;background-color:rgb(255,255,255)"> =C2=A0 =C2=A0 name_first =3D v.UnicodeString(not_empty=3DTrue)</div><div st= yle=3D"font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;back= ground-color:rgb(255,255,255)">=C2=A0 =C2=A0 name_last =3D v.UnicodeString(= not_empty=3DTrue)</div><div style=3D"font-size:13px;color:rgb(34,34,34);fon= t-family:arial,sans-serif;background-color:rgb(255,255,255)"> =C2=A0 =C2=A0 birthdate =3D IsoDate()</div></div><div style=3D"font-size:13= px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(25= 5,255,255)"><br></div><div style=3D"font-size:13px;color:rgb(34,34,34);font= -family:arial,sans-serif;background-color:rgb(255,255,255)"> <br></div><div style=3D"font-size:13px;color:rgb(34,34,34);font-family:aria= l,sans-serif;background-color:rgb(255,255,255)">-Chris</div><div style=3D"f= ont-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-c= olor:rgb(255,255,255)"> <br></div>-- <br>Christopher Lambacher<br><a href=3D"mailto:chris@kateandch= ris.net">[email protected]</a><br> </div> --14dae9cfcd16abb25904c5d59c78-- --===============2631463205679511010== 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/ --===============2631463205679511010== 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 --===============2631463205679511010==--