diff --git a/proposals/models.py b/proposals/models.py index 23eecba..ee11578 100644 --- a/proposals/models.py +++ b/proposals/models.py @@ -76,6 +76,9 @@ class Talk(PonyConfModel): event = models.ForeignKey(Event, verbose_name=_('Intervention kind')) accepted = models.NullBooleanField(default=None) + class Meta: + ordering = ('title',) + def __str__(self): return self.title diff --git a/proposals/templates/proposals/talk_list.html b/proposals/templates/proposals/talk_list.html index 9b3d21e..8b48892 100644 --- a/proposals/templates/proposals/talk_list.html +++ b/proposals/templates/proposals/talk_list.html @@ -17,13 +17,13 @@
- {% bootstrap_field filter_form.kind layout="horizontal" %} + {% bootstrap_field filter_form.kind layout="horizontal" %}
- {% bootstrap_field filter_form.status layout="horizontal" %} + {% bootstrap_field filter_form.status layout="horizontal" %}
- {% bootstrap_field filter_form.topic layout="horizontal" %} + {% bootstrap_field filter_form.topic layout="horizontal" %}
@@ -34,11 +34,11 @@ - - - - - + + + + + {% for talk in talk_list %} diff --git a/proposals/views.py b/proposals/views.py index 5fc41da..fed32de 100644 --- a/proposals/views.py +++ b/proposals/views.py @@ -65,19 +65,57 @@ def talk_list(request): show_filters = False talks = Talk.objects.filter(site=get_current_site(request)) filter_form = FilterForm(request.GET or None, site=get_current_site(request)) + # Filtering if filter_form.is_valid(): data = filter_form.cleaned_data if len(data['kind']): + show_filters = True talks = talks.filter(reduce(lambda x, y: x | y, [Q(event__pk=pk) for pk in data['kind']])) if len(data['status']): + show_filters = True talks = talks.filter(reduce(lambda x, y: x | y, [Q(accepted=dict(STATUS_VALUES)[status]) for status in data['status']])) if len(data['topic']): + show_filters = True talks = talks.filter(reduce(lambda x, y: x | y, [Q(topics__slug=topic) for topic in data['topic']])) - show_filters = True + # Sorting + if request.GET.get('order') == 'desc': + reverse = True + else: + reverse = False + SORT_MAPPING = { + 'title': 'title', + 'kind': 'event', + '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, 'proposals/talk_list.html', { 'show_filters': show_filters, 'talk_list': talks, 'filter_form': filter_form, + 'sort_urls': sort_urls, + 'sort_glyphicons': sort_glyphicons, }) @login_required
{% trans "Title" %} {% trans "Intervention kind" %} {% trans "Speakers" %} {% trans "Topics" %} {% trans "Status" %} {% trans "Title" %} {% trans "Intervention kind" %} {% trans "Speakers" %}{% trans "Topics" %}{% trans "Status" %}