[extensions-web] Revamp sorting/filtering backend
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Revamp sorting/filtering backend
- Date: Sun, 18 Dec 2011 00:50:54 +0000 (UTC)
commit 0bee7d589fdf608e761fb07e567e0e3500c7ca8d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sat Dec 17 01:58:21 2011 -0500
Revamp sorting/filtering backend
We now support sorting on arbitrary order
sweettooth/extensions/views.py | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 935fe5a..ce3611c 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -54,17 +54,15 @@ def ajax_query_params_query(request):
queryset = models.Extension.objects.filter(**query_params)
- sort = request.GET.get('sort', '')
-
- if sort == 'recent':
- queryset = queryset.order_by('-pk')
- elif sort == 'downloads':
- queryset = queryset.order_by('-downloads')
- elif sort == 'popularity':
- queryset = queryset.order_by('-popularity')
- else:
- queryset = queryset.order_by('name')
+ sort = request.GET.get('sort', 'name')
+ sort = dict(recent='created').get(sort, sort)
+ if sort not in ('created', 'downloads', 'popularity', 'name'):
+ raise Http404()
+
+ order = request.GET.get('order')
+ order = dict(desc='-', asc='').get(order, '-')
+ queryset = queryset.order_by('%s%s' % (order, sort))
return queryset
@ajax_view
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]