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

Commit

Permalink
added sort by popularity (bug 785976)
Browse files Browse the repository at this point in the history
  • Loading branch information
spasovski committed Sep 6, 2012
1 parent 2a89962 commit 3d43e71
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
14 changes: 14 additions & 0 deletions media/js/mkt/init.js
Expand Up @@ -128,6 +128,20 @@ z.page.on('fragmentloaded', function() {
// Dismiss looks like back but actually just dismisses an overlay.
$('#filters').hide();
} else if ($this.hasClass('filter')) {
// Yea...
var sortoption = z.getVars(location.href);

// This will not scale if we have more than two.
$('#filter-sort li a').removeClass('sel');
switch(sortoption.sort) {
case 'relevancy':
case 'popularity':
$('#filter-sort li.popularity a').addClass('sel');
break;
case 'rating':
$('#filter-sort li.rating a').addClass('sel');

}
$('#filters').show();
} else if ($this.hasClass('search')) {
z.body.addClass('show-search');
Expand Down
21 changes: 17 additions & 4 deletions mkt/search/templates/search/results.html
Expand Up @@ -68,10 +68,23 @@ <h2>{{ _('Filter by category') }}</h2>
{# We're not iterating over all the sort options on purpose. #}
<h2>{{ _('Sort by') }}</h2>
<ul class="toggles c" id="filter-sort">
{# TODO: This should be Popularity when on (category) browse pages. #}
<li><a href="#">{{ _('Relevancy') }}</a></li>
<li><a href="{{ search_url|urlparams(page=None, sort='rating') }}"
class="sel">{{ _('Rating') }}</a></li>
{% if active_cat %}
<li class="popularity">
<a href="{{ search_url|urlparams(page=None,
sort='popularity') }}">
{{ _('Popularity') }}
</a>
</li>
{% else %}
<li class="relevancy">
<a href="{{ search_url|urlparams(page=None, sort='None') }}">
{{ _('Relevancy') }}</a>
</li>
{% endif %}
<li class="rating">
<a href="{{ search_url|urlparams(page=None, sort='rating') }}"
class="sel">{{ _('Rating') }}</a>
</li>
</ul>
<input type="hidden" name="sort" value="">

Expand Down
27 changes: 19 additions & 8 deletions mkt/search/tests/test_views.py
Expand Up @@ -106,19 +106,30 @@ def check_cat_filter(self, params):

doc = pq(r.content)('#filter-categories')
a = pq(r.content)('#filter-categories').children('li').eq(0).find('a')
# Note: PyQuery's `hasClass` matches children's classes, so yeah.
eq_(a.attr('class'), 'sel' if not cat_selected else None,
"'Any Category' should be selected")
eq_(a.length, 1)
eq_(a.text(), 'Any Category')

a = doc('li:last').find('a')
# :last will no longer work
a = doc('li').eq(1).find('a')
eq_(a.text(), unicode(self.cat.name))
eq_(a.attr('class'), 'sel' if cat_selected else None,
'%r should be selected' % unicode(self.cat.name))
if cat_selected:
eq_(a.filter('.sel').length, 1,
'%r should be selected' % unicode(self.cat.name))
else:
eq_(a.filter('.button').length, 1,
'%r should be selected' % unicode(self.cat.name))

params.update(cat=self.cat.id)
eq_(a.attr('href'), urlparams(self.url, **params))

sorts = pq(r.content)('#filter-sort')
href = sorts('li:first-child a').attr('href')

if cat_selected:
self.assertNotEqual(href.find('sort=popularity'), -1,
'Category found - first sort option should be Popularity')
else:
eq_(href, '/search/?sort=None',
'Category found - first sort option should be Relevancy')

def test_no_cat(self):
self.check_cat_filter({})

Expand Down

0 comments on commit 3d43e71

Please sign in to comment.