improving speaker filtering
This commit is contained in:
parent
f3dd5f6cff
commit
bf2f601629
|
@ -112,25 +112,32 @@ class SpeakerFilterForm(forms.Form):
|
|||
widget=forms.CheckboxSelectMultiple,
|
||||
choices=[],
|
||||
)
|
||||
track = forms.MultipleChoiceField(
|
||||
required=False,
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
choices=[],
|
||||
)
|
||||
transport = forms.MultipleChoiceField(
|
||||
required=False,
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
choices=[('unknown', 'Not answered')] + get_options(Transport),
|
||||
choices=[('unanswered', 'Not answered'), ('unspecified', 'Not specified')] + get_options(Transport),
|
||||
)
|
||||
transport_booked = forms.NullBooleanField()
|
||||
accommodation= forms.MultipleChoiceField(
|
||||
required=False,
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
choices=[('unknown', 'Not specified')] + list(Participation.ACCOMMODATION_CHOICES),
|
||||
)
|
||||
sound = forms.NullBooleanField()
|
||||
transport_booked = forms.NullBooleanField()
|
||||
accommodation_booked = forms.NullBooleanField()
|
||||
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')
|
||||
tracks = Track.objects.filter(site=site)
|
||||
self.fields['track'].choices = [('none', 'Not assigned')] + list(tracks.values_list('slug', 'name'))
|
||||
|
||||
|
||||
class TopicForm(forms.ModelForm):
|
||||
|
|
|
@ -19,14 +19,21 @@
|
|||
<div class="col-md-6">
|
||||
{% bootstrap_field filter_form.transport layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.transport_booked layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.accommodation layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.accommodation_booked layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.sound layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.status layout="horizontal" %}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{% bootstrap_field filter_form.accommodation layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.accommodation_booked layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.status layout="horizontal" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{% bootstrap_field filter_form.topic layout="horizontal" %}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{% bootstrap_field filter_form.track layout="horizontal" %}
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success" value="{% trans "Filter" %}">
|
||||
</form>
|
||||
|
|
|
@ -347,16 +347,27 @@ def speaker_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 len(data['track']):
|
||||
show_filters = True
|
||||
q = Q()
|
||||
if 'none' in data['track']:
|
||||
data['track'].remove('none')
|
||||
q |= Q(track__isnull=True)
|
||||
if len(data['track']):
|
||||
q |= Q(track__slug__in=data['track'])
|
||||
talks = talks.filter(q)
|
||||
speakers = Participation.objects.filter(site=site,user__talk__in=talks).order_by('pk').distinct()
|
||||
if filter_form.is_valid():
|
||||
data = filter_form.cleaned_data
|
||||
if len(data['transport']):
|
||||
show_filters = True
|
||||
q = Q()
|
||||
if 'unknown' in data['transport']:
|
||||
data['transport'].remove('unknown')
|
||||
speakers = speakers.annotate(transport_count=Count('transport'))
|
||||
if 'unanswered' in data['transport']:
|
||||
data['transport'].remove('unanswered')
|
||||
q |= Q(need_transport=None)
|
||||
if 'unspecified' in data['transport']:
|
||||
data['transport'].remove('unspecified')
|
||||
speakers = speakers.annotate(transport_count=Count('transport'))
|
||||
q |= Q(need_transport=True, transport_count=0)
|
||||
if len(data['transport']):
|
||||
q |= (Q(need_transport=True) & Q(reduce(lambda x, y: x | y, [Q(transport__pk=pk) for pk in data['transport']])))
|
||||
|
|
Loading…
Reference in New Issue
Block a user