Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bug 969011] Add filter-by-country to analyzer search

  • Loading branch information...
commit ed5684e74b6bd0e207799d3f83c88a42c7710823 1 parent fe2a687
@willkg willkg authored
View
22 fjord/analytics/analyzer_views.py
@@ -31,6 +31,7 @@
check_new_user,
smart_int,
smart_date)
+from fjord.feedback.helpers import country_name
from fjord.feedback.models import Product, Response, ResponseMappingType
@@ -274,6 +275,7 @@ def analytics_search(request):
search_has_email = request.GET.get('has_email', None)
search_platform = request.GET.get('platform', None)
search_locale = request.GET.get('locale', None)
+ search_country = request.GET.get('country', None)
search_product = request.GET.get('product', None)
search_version = request.GET.get('version', None)
search_query = request.GET.get('q', None)
@@ -316,12 +318,18 @@ def unknown_to_empty(text):
f &= F(product=unknown_to_empty(search_product))
current_search['product'] = search_product
+ # Only show the version if there's a product.
if search_version is not None:
# Note: We only filter on version if we're filtering on
# product.
f &= F(version=unknown_to_empty(search_version))
current_search['version'] = search_version
+ # Only show the country if the product is Firefox OS.
+ if search_country is not None and search_product == 'Firefox OS':
+ f &= F(country=unknown_to_empty(search_country))
+ current_search['country'] = search_country
+
if search_date_start is None and search_date_end is None:
selected = '7d'
@@ -379,7 +387,8 @@ def unknown_to_empty(text):
# Navigation facet data
facets = search.facet(
- 'happy', 'platform', 'locale', 'product', 'version', 'has_email',
+ 'happy', 'platform', 'locale', 'country', 'product', 'version',
+ 'has_email',
filtered=bool(search._process_filters(f.filters)))
# This loop does two things. First it maps 'T' -> True and 'F' ->
@@ -391,6 +400,7 @@ def unknown_to_empty(text):
'has_email': {},
'platform': {},
'locale': {},
+ 'country': {},
'product': {},
'version': {},
}
@@ -440,6 +450,16 @@ def empty_to_unknown(text):
display_map=empty_to_unknown,
checked=search_version)
)
+ # Only show the country if the product is Firefox OS.
+ if search_product == 'Firefox OS':
+ filter_data.append(
+ counts_to_options(
+ counts['country'].items(),
+ name='country',
+ display='Country',
+ checked=search_country,
+ display_map=country_name),
+ )
filter_data.extend(
[
View
17 fjord/analytics/tests/test_analyzer_views.py
@@ -242,6 +242,23 @@ def test_has_email(self):
ok_('ou812' in r.content)
eq_(len(pq('li.opinion')), 1)
+ def test_country(self):
+ resp = response(
+ happy=True, product=u'Firefox OS', description=u'ou812',
+ country=u'ES', created=datetime.now(), save=True)
+ responseemail(opinion=resp, save=True)
+ # Have to reindex everything because unlike in a request
+ # context, what happens here is we index the Response, but
+ # without the ResponseEmail.
+ self.setup_indexes()
+
+ r = self.client.get(self.url, {
+ 'product': 'Firefox OS', 'country': 'ES'})
+ eq_(r.status_code, 200)
+ pq = PyQuery(r.content)
+ ok_('ou812' in r.content)
+ eq_(len(pq('li.opinion')), 1)
+
def test_empty_and_unknown(self):
# Empty value should work
r = self.client.get(self.url, {'platform': ''})
View
2  fjord/feedback/models.py
@@ -170,6 +170,7 @@ def get_mapping(cls):
'browser_version': keyword_type(),
'platform': keyword_type(),
'locale': keyword_type(),
+ 'country': keyword_type(),
'device': keyword_type(),
'manufacturer': keyword_type(),
'created': date_type()
@@ -198,6 +199,7 @@ def empty_to_unknown(text):
'browser_version': obj.browser_version,
'platform': obj.platform,
'locale': obj.locale,
+ 'country': obj.country,
'device': obj.device,
'manufacturer': obj.manufacturer,
'created': obj.created,
Please sign in to comment.
Something went wrong with that request. Please try again.