Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Fixes for device/manufacture faceting.
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Dec 8, 2010
1 parent d8defda commit 362ecf5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 24 deletions.
17 changes: 11 additions & 6 deletions apps/dashboard/templates/dashboard/devices.html
@@ -1,9 +1,11 @@
{% macro device_item(device, count=0, selected=False) %}
<li>
<input id="device_{{ device }}" name="device" value="{{ device }}"
<input id="device_{{ device }}" name="device"
value="{{ device or 'Unknown' }}"
{{ 'disabled' if defaults['manufacturer'] and not device }}
type="checkbox" {{ 'checked' if selected else '' }} />
<label for="device_{{ device }}" class="bar {{ 'selected' if selected else '' }}" data-value="{{ count }}">
<strong>{{ device }}</strong>
<strong>{{ device or _('Unknown') }}</strong>
</label>
</li>
{% endmacro %}
Expand All @@ -13,10 +15,13 @@
{{ filter_box_toggle(_('Devices')) }}

<ul class="bars" data-total="{{ total }}">

{% for item in devices %}
{{ device_item(item.device, item.count) }}
{% endfor %}
{% if defaults['device'] %}
{{ device_item(defaults['device'], selected=True) }}
{% else %}
{% for item in devices[:15] %}
{{ device_item(item.device, item.count) }}
{% endfor %}
{% endif %}
</ul>
</div>
{% endif %}
2 changes: 1 addition & 1 deletion apps/dashboard/templates/dashboard/locales.html
Expand Up @@ -18,7 +18,7 @@
{% if defaults['locale'] %}
{{ locale_item(defaults['locale'], selected=True) }}
{% else %}
{% for item in locales %}
{% for item in locales[:15] %}
{{ locale_item(item.locale, item.count) }}
{% endfor %}
{% endif %}
Expand Down
13 changes: 9 additions & 4 deletions apps/dashboard/templates/dashboard/manufacturers.html
@@ -1,6 +1,7 @@
{% macro brand_item(manufacturer, count=0, selected=False) %}
<li>
<input id="brand_{{ manufacturer }}" name="brand" value="{{ manufacturer }}"
<input id="brand_{{ manufacturer }}" name="manufacturer"
value="{{ manufacturer or 'Unknown' }}"
type="checkbox" {{ 'checked' if selected else '' }} />
<label for="brand_{{ manufacturer }}"
class="bar {{ 'selected' if selected else '' }}"
Expand All @@ -15,9 +16,13 @@
{{ filter_box_toggle(_('Manufacturer')) }}

<ul class="bars" data-total="{{ total }}">
{% for item in manufacturers %}
{{ brand_item(item.manufacturer, item.count) }}
{% endfor %}
{% if defaults['manufacturer'] %}
{{ brand_item(defaults['manufacturer'], selected=True) }}
{% else %}
{% for item in manufacturers %}
{{ brand_item(item.manufacturer, item.count) }}
{% endfor %}
{% endif %}
</ul>
</div>
{% endif %}
6 changes: 3 additions & 3 deletions apps/feedback/helpers.py
Expand Up @@ -13,7 +13,7 @@ def os_name(os):


@register.function
def locale_name(locale, native=False, default=_lazy('unknown')):
def locale_name(locale, native=False, default=_lazy('Unknown')):
"""Convert a locale code into a human readable locale name."""
if locale in product_details.languages:
return product_details.languages[locale][
Expand All @@ -31,10 +31,10 @@ def smiley(style, page=None):
"""
if not style in ('happy', 'sad'):
return ''
if style == 'happy': # positive smiley
if style == 'happy': # positive smiley
character = '&#9786;'
title = _('Praise')
else: # negative smiley
else: # negative smiley
character = '&#9785;'
title = _('Issue')
return jinja2.Markup(
Expand Down
6 changes: 5 additions & 1 deletion apps/search/client.py
Expand Up @@ -59,7 +59,11 @@ def extract_filters(kwargs):
metas['type'] = kwargs['type']

for meta in ('os', 'manufacturer', 'device'):
if kwargs.get(meta):
val = kwargs.get(meta)
if val and val.lower() == 'unknown':
# In this situation 'unknown' usually means empty.
metas[meta] = crc32('')
elif val:
metas[meta] = crc32(kwargs[meta])

if kwargs.get('locale'):
Expand Down
18 changes: 14 additions & 4 deletions apps/search/forms.py
Expand Up @@ -6,8 +6,9 @@
from product_details import product_details
from tower import ugettext_lazy as _lazy

from feedback import FIREFOX, MOBILE, OS_USAGE, OPINION_TYPES
from feedback import FIREFOX, MOBILE, OS_USAGE
from feedback.version_compare import simplify_version, version_int
from input import KNOWN_DEVICES, KNOWN_MANUFACTURERS
from input.fields import DateInput, SearchInput
from input.utils import uniquifier

Expand All @@ -34,17 +35,23 @@
SENTIMENT_CHOICES = [('', _lazy('-- all --', 'sentiment_choice')),
('happy', _lazy('Praise')),
('sad', _lazy('Issues')),
('suggestions', _lazy('Suggestions'))
('suggestions', _lazy('Suggestions')),
]
SENTIMENTS = ('happy', 'sad', 'suggestions')

SENTIMENTS = ('happy', 'sad', 'suggestions')

OS_CHOICES = ([('', _lazy('-- all --', 'os_choice'))] +
[(o.short, o.pretty) for o in OS_USAGE])

MANUFACTURER_CHOICES = [('Unknown', _lazy('Unknown'))] + [(m, m) for m in
KNOWN_MANUFACTURERS]

DEVICE_CHOICES = [('Unknown', _lazy('Unknown'))] + [(d, d) for d in
KNOWN_DEVICES]

LOCALE_CHOICES = [
('', _lazy('-- all --', 'locale_choice')),
('unknown', _lazy('unknown')),
('Unknown', _lazy('Unknown')),
] + [(lang, lang) for lang in sorted(product_details.languages)]


Expand All @@ -61,6 +68,9 @@ class ReporterSearchForm(forms.Form):
choices=LOCALE_CHOICES)
os = forms.ChoiceField(required=False, label=_lazy('OS:'),
choices=OS_CHOICES)
manufacturer = forms.ChoiceField(required=False,
choices=MANUFACTURER_CHOICES)
device = forms.ChoiceField(required=False, choices=DEVICE_CHOICES)
date_start = forms.DateField(required=False, widget=DateInput(
attrs={'class': 'datepicker'}), label=_lazy('Date range:'))
date_end = forms.DateField(required=False, widget=DateInput(
Expand Down
10 changes: 5 additions & 5 deletions apps/search/templates/search/search.html
Expand Up @@ -31,12 +31,12 @@ <h3>{{ _('Product') }}</h3>
{# TODO URL provided box #}

{{ platforms_block(demo.os, opinion_count, defaults=defaults) }}
{% if product == 'mobile' %}
{{ manufacturer_block(demo.manufacturer, opinion_count,
defaults=defaults) }}

{{ manufacturer_block(demo.manufacturer, opinion_count,
defaults=defaults) }}

{{ device_block(demo.device, opinion_count, defaults=defaults) }}

{{ device_block(demo.device, opinion_count, defaults=defaults) }}
{% endif %}
{{ locales_block(demo.locale, opinion_count, defaults=defaults) }}

</form>
Expand Down
17 changes: 17 additions & 0 deletions apps/search/tests.py
Expand Up @@ -143,12 +143,29 @@ class SearchViewTest(SphinxTestCase):
def setUp(self):
# add more opinions so we can test things.
populate(100, 'desktop')
populate(100)
super(SearchViewTest, self).setUp()

def test_pagination_max(self):
r = search_request(page=700)
self.failUnlessEqual(r.status_code, 200)

def test_filters(self):
"""
Make sure Manufacturer and Device filters don't show up on search for
desktop.
"""
r = search_request()
doc = pq(r.content)
filters = doc('.filter h3 a')
assert not any(['Manufacturer' in f.text_content() for f in filters])
assert not any(['Device' in f.text_content() for f in filters])
r = search_request(product='mobile')
doc = pq(r.content)
filters = doc('.filter h3 a')
assert any(['Manufacturer' in f.text_content() for f in filters])
assert any(['Device' in f.text_content() for f in filters])

def compare_2_pages(self, page1, page2):
r = search_request(page=page1)
doc = pq(r.content)
Expand Down

0 comments on commit 362ecf5

Please sign in to comment.