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

[bug 949000] Switch product list to dropdown #197

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,11 @@ <h3>Product</h3>

<div class="container">
<label for="id_product">Product</label>
<input id="id_product" type="text" name="product" value="{{ form.product.value() }}" />
<select id="id_product" name="product">
{% for prod in products %}
<option value="{{ prod }}"{% if form.product.value() == prod %} selected{% endif %}>{{ prod }}</option>
{% endfor %}
</select>
{{ form.product.errors }}
</div>
</li>
Expand Down
7 changes: 7 additions & 0 deletions fjord/analytics/views.py
Expand Up @@ -470,6 +470,7 @@ def analytics_dashboard(request, template):

@check_new_user
@analyzer_required
@es_required_or_50x(error_template='analytics/es_down.html')
def analytics_occurrences_comparison(request):
template = 'analytics/analytics_occurrences_comparison.html'

Expand Down Expand Up @@ -607,9 +608,15 @@ def analytics_occurrences_comparison(request):
permalink = ''
form = OccurrencesComparisonForm()

# FIXME - We have responses that have no product set. This ignores
# those. That's probably the right thing to do for the Occurrences Report
# but maybe not.
products = [prod for prod in ResponseMappingType.get_products() if prod]

return render(request, template, {
'permalink': permalink,
'form': form,
'products': products,
'first_facet_bi': first_facet_bi,
'first_params': first_params,
'first_facet_total': first_facet_total,
Expand Down
19 changes: 19 additions & 0 deletions fjord/feedback/models.py
@@ -1,5 +1,6 @@
from datetime import datetime

from django.core.cache import cache
from django.db import models

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

@classmethod
def get_products(cls):
"""Returns a list of all products

This is cached.

"""
key = 'feedback:response_products1'
products = cache.get(key)
if products is not None:
return products

facet = cls.search().facet('product').facet_counts()
products = [prod['term'] for prod in facet['product']]

cache.add(key, products)
return products


class ResponseEmail(ModelBase):
"""Holds email addresses related to Responses."""
Expand Down