Skip to content

Commit

Permalink
Fixes bug 1200596 - DateTimeField now parses all types of dates and t…
Browse files Browse the repository at this point in the history
…imes.
  • Loading branch information
adngdb committed Oct 8, 2015
1 parent 5ff27aa commit 067e5bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions webapp-django/crashstats/signature/views.py
Expand Up @@ -281,8 +281,8 @@ def signature_graphs(request, field):
# pick it up.
return http.HttpResponseBadRequest('<ul><li>%s</li></ul>' % e)

data['aggregates'] = search_results['facets']['histogram_date']
data['term_counts'] = search_results['facets'][field]
data['aggregates'] = search_results['facets'].get('histogram_date', [])
data['term_counts'] = search_results['facets'].get(field, [])

return data

Expand Down
17 changes: 10 additions & 7 deletions webapp-django/crashstats/supersearch/form_fields.py
Expand Up @@ -112,19 +112,22 @@ class IntegerField(MultiplePrefixedValueField, forms.IntegerField):
pass


class DateTimeField(MultiplePrefixedValueField, forms.DateTimeField):
def value_to_string(self, value):
if value:
return value.isoformat()

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

return super(IsoDateTimeField, self).to_python(value)


class DateTimeField(MultiplePrefixedValueField, IsoDateTimeField):
def value_to_string(self, value):
if value:
return value.isoformat()


class StringField(MultipleValueField):
Expand Down
14 changes: 14 additions & 0 deletions webapp-django/crashstats/supersearch/tests/test_form_fields.py
Expand Up @@ -28,6 +28,20 @@ def test_datetime_field(self):
eq_(cleaned_value, [dt])
eq_(field.prefixed_value, ['>2012-12-31T10:20:30+00:00'])

field = form_fields.DateTimeField()
cleaned_value = field.clean(['>=2012-12-31'])
dt = datetime.datetime(2012, 12, 31)
dt = dt.replace(tzinfo=utc)
eq_(cleaned_value, [dt])
eq_(field.prefixed_value, ['>=2012-12-31T00:00:00+00:00'])

field = form_fields.DateTimeField()
cleaned_value = field.clean(['>=2012-12-31T01:02:03+00:00'])
dt = datetime.datetime(2012, 12, 31, 1, 2, 3)
dt = dt.replace(tzinfo=utc)
eq_(cleaned_value, [dt])
eq_(field.prefixed_value, ['>=2012-12-31T01:02:03+00:00'])

def test_several_fields(self):
field1 = form_fields.DateTimeField()
cleaned_value1 = field1.clean(['>12/31/2012 10:20:30'])
Expand Down

0 comments on commit 067e5bb

Please sign in to comment.