Created
September 25, 2013 01:52
-
-
Save andymccurdy/6694168 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wtforms | |
class DummyPostData(dict): | |
def getlist(self, key): | |
v = self[key] | |
if not isinstance(v, (list, tuple)): | |
v = [v] | |
return v | |
class MyForm(wtforms.Form): | |
datetime_field = wtforms.DateTimeField( | |
validators=[wtforms.validators.Required()] | |
) | |
post_data = DummyPostData({'datetime_field': '2013-09-24 00:00'}) | |
form = MyForm(post_data) | |
form.validate() | |
# this fails validation because the format doesn't match the field's format | |
# however, when the Required() validator is on the field, like it is above, | |
# the error message is: | |
In [2]: form.errors | |
Out[2]: {'datetime_field': [u'This field is required.']} | |
# instead of 'Not a valid datetime value', which is what it should be |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment