diff --git a/proposals/forms.py b/proposals/forms.py index 0d90a0e..ae52684 100644 --- a/proposals/forms.py +++ b/proposals/forms.py @@ -55,6 +55,7 @@ class TalkFilterForm(forms.Form): widget=forms.CheckboxSelectMultiple, choices=[], ) + def __init__(self, *args, **kwargs): site = kwargs.pop('site') super().__init__(*args, **kwargs) @@ -65,6 +66,11 @@ class TalkFilterForm(forms.Form): class SpeakerFilterForm(forms.Form): + topic = forms.MultipleChoiceField( + required=False, + widget=forms.CheckboxSelectMultiple, + choices=[], + ) transport = forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, @@ -79,8 +85,12 @@ class SpeakerFilterForm(forms.Form): ], ) sound = forms.NullBooleanField() + def __init__(self, *args, **kwargs): + site = kwargs.pop('site') super().__init__(*args, **kwargs) + topics = Topic.objects.filter(site=site) + self.fields['topic'].choices = topics.values_list('slug', 'name') class TopicCreateForm(forms.ModelForm): diff --git a/proposals/templates/proposals/speaker_list.html b/proposals/templates/proposals/speaker_list.html index 91172ee..ed46a8c 100644 --- a/proposals/templates/proposals/speaker_list.html +++ b/proposals/templates/proposals/speaker_list.html @@ -21,9 +21,10 @@
{% bootstrap_field filter_form.hosting layout="horizontal" %} + {% bootstrap_field filter_form.sound layout="horizontal" %}
- {% bootstrap_field filter_form.sound layout="horizontal" %} + {% bootstrap_field filter_form.topic layout="horizontal" %}
diff --git a/proposals/views.py b/proposals/views.py index cdc1089..cf89b47 100644 --- a/proposals/views.py +++ b/proposals/views.py @@ -238,10 +238,15 @@ def talk_decide(request, talk, accepted): def speaker_list(request): show_filters = False site = get_current_site(request) + filter_form = SpeakerFilterForm(request.GET or None, site=site) talks = Talk.objects.filter(site=site) - speakers = Participation.objects.filter(user__talk__in=talks).all().distinct() - filter_form = SpeakerFilterForm(request.GET or None) # Filtering + if filter_form.is_valid(): + data = filter_form.cleaned_data + 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']])) + speakers = Participation.objects.filter(user__talk__in=talks).all().distinct() if filter_form.is_valid(): data = filter_form.cleaned_data if len(data['transport']):