This commit is contained in:
Chris Van 2011-10-15 04:00:30 -07:00
Родитель 286fd9dbab
Коммит 1e5908a5af
4 изменённых файлов: 46 добавлений и 4 удалений

Просмотреть файл

@ -393,13 +393,18 @@ def is_choice_field(value):
@register.inclusion_tag('amo/mobile/sort_by.html')
def mobile_sort_by(base_url, options={}, selected=None, search_filter=None):
def mobile_sort_by(base_url, options=None, selected=None, extra_sort_opts=None,
search_filter=None):
if search_filter:
selected = search_filter.field
options = search_filter.opts
if hasattr(search_filter, 'extras'):
options += search_filter.extras
current = [title for key, title in options if key == selected][0]
options_dict = dict(options)
if selected in options_dict:
current = options_dict[selected]
else:
selected, current = options[0] # Default to the first option.
return locals()

Просмотреть файл

@ -1,7 +1,7 @@
{% extends "mobile/base.html" %}
{% block title %}
{% if query %}
{% if query.q %}
{# L10n: {0} is a search query. #}
{{ page_title(_('{0} :: Search')|f(query.q)) }}
{% else %}
@ -24,7 +24,7 @@
{% include "search/mobile/search.html" %}
{% endwith %}
</div>
{{ mobile_sort_by(request.get_full_path(), sort_opts, query.sort) }}
{{ mobile_sort_by(request.get_full_path(), sort_opts, query.sort, extra_sort_opts) }}
<div class="addon-listing">
<ul class="listview">

Просмотреть файл

@ -112,6 +112,41 @@ class TestESSearch(amo.tests.ESTestCase):
eq_(r.status_code, 200)
self.assertTemplateUsed(r, 'search/mobile/results.html')
def check_sort_links(self, key, title, sort_by=None, reverse=True):
r = self.client.get('%s?sort=%s' % (self.url, key))
eq_(r.status_code, 200)
menu = pq(r.content)('#sort-menu')
eq_(menu.find('span').text(), title)
eq_(menu.find('li.selected').text(), title)
if sort_by:
a = r.context['pager'].object_list
eq_(list(a),
sorted(a, key=lambda x: getattr(x, sort_by), reverse=reverse))
@amo.tests.mobile_test
def test_mobile_results_sort_default(self):
self.check_sort_links('relevance', 'Relevance', 'weekly_downloads')
@amo.tests.mobile_test
def test_mobile_results_sort_relevance(self):
self.check_sort_links('relevance', 'Relevance')
@amo.tests.mobile_test
def test_mobile_results_sort_users(self):
self.check_sort_links('users', 'Most Users', 'average_daily_users')
@amo.tests.mobile_test
def test_mobile_results_sort_rating(self):
self.check_sort_links('rating', 'Top Rated', 'bayesian_rating')
@amo.tests.mobile_test
def test_mobile_results_sort_newest(self):
self.check_sort_links('created', 'Newest', 'created')
@amo.tests.mobile_test
def test_mobile_results_sort_unknown(self):
self.check_sort_links('updated', 'Relevance')
def test_legacy_redirects(self):
r = self.client.get(self.url + '?sort=averagerating')
self.assertRedirects(r, self.url + '?sort=rating', status_code=301)

Просмотреть файл

@ -1374,6 +1374,8 @@ li.persona-previewer {
.badges .warning {
background-color: #fef9d7;
border-color: #bebaa1;
}
.badges .warning span {
cursor: pointer;
}
.install .privacy-policy {