Skip to content

Instantly share code, notes, and snippets.

@andymccurdy
Created September 25, 2013 01:52
Show Gist options
  • Save andymccurdy/6694168 to your computer and use it in GitHub Desktop.
Save andymccurdy/6694168 to your computer and use it in GitHub Desktop.
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