Igor Murashkin wrote:
Hello everyone,I am trying to validate a really simple form, something like this: { 'names' : ['James', 'Book'], 'zips':['12345', '20093'], 'id':'5', 'misc':'foo'] } for a method like processForm(names, zips, id, misc) However, while making a schema for id and misc is simple (using validators.Int() and validators.String()), I have hit a dead end when looking for a way to validate a *list* of integers or a list of strings. According to the FormEncode documentation, http://www.formencode.org/module-formencode.foreach.html, ForEach(AsInt(), InList([1, 2, 3])) would validate the [1,2,3] as a list of integers. However I cannot find AsInt() or InList() definitions *anywhere* in formencode package or in all of turbogears for that matter (yes, I grepped it).
I think the documentation is out of date, it should be foreach.ForEach(validators.OneOf([1, 2, 3]), validators.Int()), which should be equivalent to ForEach(All(validators.OneOf([1, 2, 3]), validators.Int()))
I know there is a way of writing custom validators, but I don't think that's pythonic or even correct at all. It would be like copying-and-pasting every time I needed to validate a list. There's got to be an existing way to validate lists of something, right?
ForEach is what you want; it takes as arguments validator(s) that will be applied to a list.
-- Ian Bicking | [EMAIL PROTECTED] | http://blog.ianbicking.org ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ FormEncode-CVS mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/formencode-cvs
