filter speakers by topics
This commit is contained in:
parent
137c514f60
commit
b556f2b6de
|
@ -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):
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
</div>
|
||||
<div class="col-md-4 col-xs-6">
|
||||
{% bootstrap_field filter_form.hosting layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.sound layout="horizontal" %}
|
||||
</div>
|
||||
<div class="col-md-4 col-xs-6">
|
||||
{% bootstrap_field filter_form.sound layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.topic layout="horizontal" %}
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success" value="{% trans "Filter" %}">
|
||||
|
|
|
@ -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']):
|
||||
|
|
Loading…
Reference in New Issue