Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #329 from AdrianGaudebert/864805-default-date-in-s…

…earch

Fixes bug 864805 - Made minutes and seconds 0 in default datetime in search
  • Loading branch information...
commit 83651360a8d56da7f56968bdfb78e5e90b4903e2 2 parents d70e4e1 + 32fec88
@AdrianGaudebert AdrianGaudebert authored
View
4 crashstats/crashstats/forms.py
@@ -1,5 +1,4 @@
import re
-import datetime
import collections
from django import forms
@@ -112,9 +111,6 @@ def __init__(self, current_products, current_versions, current_platforms,
def clean_product(self):
return self.cleaned_data['product'] or [settings.DEFAULT_PRODUCT]
- def clean_date(self):
- return self.cleaned_data['date'] or datetime.datetime.utcnow()
-
def clean_range_value(self):
value = self.cleaned_data['range_value']
if not value:
View
1  crashstats/crashstats/tests/test_forms.py
@@ -136,7 +136,6 @@ def get_new_form(data):
'plugin_field': 'filename'})
ok_(form.is_valid())
- ok_(isinstance(form.cleaned_data['date'], datetime.datetime))
eq_(form.cleaned_data['product'], [settings.DEFAULT_PRODUCT])
eq_(form.cleaned_data['version'], [])
eq_(form.cleaned_data['platform'], [])
View
13 crashstats/crashstats/tests/test_views.py
@@ -1421,6 +1421,19 @@ def mocked_get(url, **options):
ok_('table id="signatureList"' in response.content)
ok_('nsASDOMWindowEnumerator::GetNext()' in response.content)
+ # Test defaut date
+ expected = datetime.datetime.utcnow()
+ response = self.client.get(url)
+ eq_(response.status_code, 200)
+ ok_(expected.strftime('%m/%d/%Y %H:00:00') in response.content)
+
+ # Test passed date
+ response = self.client.get(url, {
+ 'date': '11/27/2085 10:10:10'
+ })
+ eq_(response.status_code, 200)
+ ok_('11/27/2085 10:10:10' in response.content)
+
@mock.patch('requests.post')
@mock.patch('requests.get')
def test_query_summary(self, rget, rpost):
View
17 crashstats/crashstats/views.py
@@ -928,7 +928,7 @@ def report_list(request):
else:
data['product_versions'] = ['ALL:ALL']
- end_date = form.cleaned_data['date']
+ end_date = form.cleaned_data['date'] or datetime.datetime.utcnow()
if form.cleaned_data['range_unit']:
range_unit = form.cleaned_data['range_unit']
@@ -1227,6 +1227,19 @@ def query(request):
data['product'] = form.cleaned_data['product'][0]
+ if not form.cleaned_data['date']:
+ date = datetime.datetime.utcnow()
+ # This is an optimization for elasticsearch.
+ # If the user supplies a value for 'date', we just use that but
+ # if no value is sent, then the default one is less precise,
+ # which means users will often use the same value for date
+ # (assuming they don't change that value).
+ # In the backend, we end up with more common date filters
+ # thus improving performance.
+ date = date.replace(minute=0, second=0, microsecond=0)
+ else:
+ date = form.cleaned_data['date']
+
try:
data['current_page'] = int(request.GET.get('page', 1))
except ValueError:
@@ -1288,7 +1301,7 @@ def query(request):
'products': form.cleaned_data['product'],
'versions': form.cleaned_data['version'],
'platforms': form.cleaned_data['platform'],
- 'end_date': form.cleaned_data['date'],
+ 'end_date': date,
'date_range_unit': range_unit,
'date_range_value': form.cleaned_data['range_value'],
'query_type': query_type,
Please sign in to comment.
Something went wrong with that request. Please try again.