Skip to content
This repository was archived by the owner on Jan 31, 2018. It is now read-only.

Commit e951be8

Browse files
committed
[bug 949000] Switch product list to dropdown
The occurrences report now uses a dropdown list of all available products.
1 parent e16ce46 commit e951be8

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

fjord/analytics/templates/analytics/analytics_occurrences_comparison.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ <h3>Product</h3>
2020

2121
<div class="container">
2222
<label for="id_product">Product</label>
23-
<input id="id_product" type="text" name="product" value="{{ form.product.value() }}" />
23+
<select id="id_product" name="product">
24+
{% for prod in products %}
25+
<option value="{{ prod }}"{% if form.product.value() == prod %} selected{% endif %}>{{ prod }}</option>
26+
{% endfor %}
27+
</select>
2428
{{ form.product.errors }}
2529
</div>
2630
</li>

fjord/analytics/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def analytics_dashboard(request, template):
470470

471471
@check_new_user
472472
@analyzer_required
473+
@es_required_or_50x(error_template='analytics/es_down.html')
473474
def analytics_occurrences_comparison(request):
474475
template = 'analytics/analytics_occurrences_comparison.html'
475476

@@ -607,9 +608,15 @@ def analytics_occurrences_comparison(request):
607608
permalink = ''
608609
form = OccurrencesComparisonForm()
609610

611+
# FIXME - We have responses that have no product set. This ignores
612+
# those. That's probably the right thing to do for the Occurrences Report
613+
# but maybe not.
614+
products = [prod for prod in ResponseMappingType.get_products() if prod]
615+
610616
return render(request, template, {
611617
'permalink': permalink,
612618
'form': form,
619+
'products': products,
613620
'first_facet_bi': first_facet_bi,
614621
'first_params': first_params,
615622
'first_facet_total': first_facet_total,

fjord/feedback/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22

3+
from django.core.cache import cache
34
from django.db import models
45

56
from elasticutils.contrib.django import Indexable
@@ -184,6 +185,24 @@ def truncated_description(self):
184185
"""Shorten feedback for dashboard view."""
185186
return smart_truncate(self.description, length=500)
186187

188+
@classmethod
189+
def get_products(cls):
190+
"""Returns a list of all products
191+
192+
This is cached.
193+
194+
"""
195+
key = 'feedback:response_products1'
196+
products = cache.get(key)
197+
if products is not None:
198+
return products
199+
200+
facet = cls.search().facet('product').facet_counts()
201+
products = [prod['term'] for prod in facet['product']]
202+
203+
cache.add(key, products)
204+
return products
205+
187206

188207
class ResponseEmail(ModelBase):
189208
"""Holds email addresses related to Responses."""

0 commit comments

Comments
 (0)