filter topic by vote status

This commit is contained in:
Élie Bouttier 2016-09-21 22:35:36 +02:00
parent 04d3dc99f4
commit ba88c76b8a
3 changed files with 7 additions and 0 deletions

View File

@ -55,6 +55,7 @@ class TalkFilterForm(forms.Form):
widget=forms.CheckboxSelectMultiple,
choices=[],
)
vote = forms.NullBooleanField(help_text='Filter topics you already / not yet voted for')
def __init__(self, *args, **kwargs):
site = kwargs.pop('site')

View File

@ -21,6 +21,7 @@
</div>
<div class="col-md-4 col-xs-6">
{% bootstrap_field filter_form.status layout="horizontal" %}
{% bootstrap_field filter_form.vote layout="horizontal" %}
</div>
<div class="col-md-4 col-xs-6">
{% bootstrap_field filter_form.topic layout="horizontal" %}

View File

@ -77,6 +77,11 @@ def talk_list(request):
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']]))
if data['vote'] != None:
if data['vote']:
talks = talks.filter(vote__user=request.user)
else:
talks = talks.exclude(vote__user=request.user)
# Sorting
if request.GET.get('order') == 'desc':
reverse = True