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

Commit

Permalink
Merge pull request #146 from pennyfx/sort-fix
Browse files Browse the repository at this point in the history
Fixed sorting issue: 738469
  • Loading branch information
pennyfx committed May 7, 2012
2 parents ed2e0c0 + c4ce187 commit 542d4c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 0 additions & 10 deletions apps/base/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ def querystring(context, query, **params):
return '&'.join(sorted(qs))


@jinja2.contextfunction
@register.function
def select_selected(context, value):
bits = value.split('=');
if context['request'].GET.get(bits[0]) == bits[1]:
return 'selected=selected'
else:
return ''


@register.function
def replace(item, value):
"""Replaces first part of ``value`` with the second one
Expand Down
11 changes: 11 additions & 0 deletions apps/search/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from elasticutils import S, F
from jetpack.models import Package
from jingo import register
import jinja2


def package_search(searchq='', user=None, score_on=None, **filters):
Expand Down Expand Up @@ -110,3 +111,13 @@ def _get_average_activity():

cache.set(ACTIVITY_CACHE_KEY, average, 60*60*24)
return average


@jinja2.contextfunction
@register.function
def select_selected(context, value):
bits = value.split('=');
if context['request'].GET.get(bits[0]) == bits[1] or context.get('query')[bits[0]] == bits[1]:
return 'selected=selected'
else:
return ''
9 changes: 8 additions & 1 deletion apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ def search(request):
limit = 20
activity_map = get_activity_scale()

sort = SORT_MAPPING.get(query.get('sort'), '_score' if q else '-activity')
if q and query.get('sort') == '':
sort = '_score'
query['sort'] = 'score'
elif query.get('sort') == '':
sort = '-activity'
query['sort'] = 'activity'
else:
sort = SORT_MAPPING.get(query.get('sort'))

filters = {}
filters['user'] = request.user
Expand Down

0 comments on commit 542d4c3

Please sign in to comment.