Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DateTimeField with isoformat parsing support
  • Loading branch information
peterbe authored and adngdb committed Oct 8, 2015
1 parent 8514aa5 commit 5ff27aa
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions webapp-django/crashstats/supersearch/form_fields.py
Expand Up @@ -114,17 +114,17 @@ class IntegerField(MultiplePrefixedValueField, forms.IntegerField):

class DateTimeField(MultiplePrefixedValueField, forms.DateTimeField):
def value_to_string(self, value):
try:
if value:
return value.isoformat()
except AttributeError: # when value is None
return value

def strptime(self, value, format):
try:
d = isodate.parse_datetime(value)
return d.replace(tzinfo=utc)
except ValueError:
return super(DateTimeField, self).strptime(value, format)

def to_python(self, value):
if value:
try:
return isodate.parse_datetime(value).replace(tzinfo=utc)
except ValueError:
# let the super method deal with that
pass
return super(DateTimeField, self).to_python(value)


class StringField(MultipleValueField):
Expand Down

0 comments on commit 5ff27aa

Please sign in to comment.