date filter should not crash when dealing with non date objects
I'm using date filter on a form field like so: {{ form.field.data|date:"m-d-Y" }} When loading the form for editing, all is well. However, if validation fails for the form, date fields are sent back as unicode and not date objects. The date filter throws an error.
As a workaround, I wrote a wrapper for the date filter which puts it in a try/except block, returning the value if 'date' fails. This works but feels hacky.
milestone: |
→ 1.1
|
Triage Stage: |
Unreviewed → Accepted
|
Cc: |
Nicolás Miyasato added
|
Keywords: |
pycamp2009 added
|
Owner: |
changed from nobody to Andrew Badr
|
Owner: |
changed from Andrew Badr to Eric Holscher
|
Status: |
new → assigned
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
The attachment implements the behavior described in the ticket, returning value if there is an exception. It patches the time filter in addition to date since the two cases are directly analogous. Only catches AttributeError since that's what you get when you pass a string to format or time_format. I'd prefer to raise an exception if value can't be formatted and is not a basestring.