From 2aecfe3abebc81c6e715f9877f94296e82525ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Tue, 1 Aug 2017 14:00:31 +0200 Subject: [PATCH] sort talks --- cfp/templates/cfp/staff/talk_list.html | 2 +- cfp/views.py | 35 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/cfp/templates/cfp/staff/talk_list.html b/cfp/templates/cfp/staff/talk_list.html index cbb603a..8271152 100644 --- a/cfp/templates/cfp/staff/talk_list.html +++ b/cfp/templates/cfp/staff/talk_list.html @@ -13,7 +13,7 @@ {% comment %}{% endcomment %} {% trans "Title" %} - {% trans "Intervention kind" %} + {% trans "Intervention kind" %} {% trans "Speakers" %} {% trans "Track" %} {% trans "Status" %} diff --git a/cfp/views.py b/cfp/views.py index 2e58138..fe085cc 100644 --- a/cfp/views.py +++ b/cfp/views.py @@ -132,8 +132,43 @@ def staff(request, conference): @staff_required def talk_list(request, conference): talks = Talk.objects.filter(site=conference.site) + # Sorting + if request.GET.get('order') == 'desc': + reverse = True + else: + reverse = False + SORT_MAPPING = { + 'title': 'title', + 'category': 'category', + 'status': 'accepted', + } + sort = request.GET.get('sort') + if sort in SORT_MAPPING.keys(): + if reverse: + talks = talks.order_by('-' + SORT_MAPPING[sort]) + else: + talks = talks.order_by(SORT_MAPPING[sort]) + # Sorting URLs + sort_urls = dict() + sort_glyphicons = dict() + for c in SORT_MAPPING.keys(): + url = request.GET.copy() + url['sort'] = c + if c == sort: + if reverse: + del url['order'] + glyphicon = 'sort-by-attributes-alt' + else: + url['order'] = 'desc' + glyphicon = 'sort-by-attributes' + else: + glyphicon = 'sort' + sort_urls[c] = url.urlencode() + sort_glyphicons[c] = glyphicon return render(request, 'cfp/staff/talk_list.html', { 'talk_list': talks, + 'sort_urls': sort_urls, + 'sort_glyphicons': sort_glyphicons, })