manager: add status filter on check page (#61974)
This commit is contained in:
parent
86f7cda771
commit
7432ced673
|
@ -331,9 +331,9 @@ class BookingCheckFilterSet(django_filters.FilterSet):
|
|||
filters = kwargs.pop('filters')
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# add filters to filterset
|
||||
# add filters on extra_data to filterset
|
||||
for key, values in filters.items():
|
||||
self.filters[key] = django_filters.ChoiceFilter(
|
||||
self.filters['extra-data-%s' % key] = django_filters.ChoiceFilter(
|
||||
label=_('Filter by %s') % key,
|
||||
field_name='extra_data__%s' % key,
|
||||
lookup_expr='iexact',
|
||||
|
@ -356,6 +356,47 @@ class BookingCheckFilterSet(django_filters.FilterSet):
|
|||
)
|
||||
self.filters['sort'].parent = self
|
||||
|
||||
# add filters on booking status to filterset
|
||||
status_choices = [
|
||||
('booked', _('With booking')),
|
||||
('not-booked', _('Without booking')),
|
||||
('cancelled', _('Cancelled')),
|
||||
('not-checked', _('Not checked')),
|
||||
('presence', _('Presence')),
|
||||
('absence', _('Absence')),
|
||||
]
|
||||
if self.agenda.absence_reasons_group:
|
||||
status_choices += [
|
||||
('absence-%s' % r.label, _('Absence (%s)') % r.label)
|
||||
for r in self.agenda.absence_reasons_group.absence_reasons.all()
|
||||
]
|
||||
self.filters['booking-status'] = django_filters.ChoiceFilter(
|
||||
label=_('Filter by status'),
|
||||
choices=status_choices,
|
||||
empty_label=_('all'),
|
||||
widget=forms.RadioSelect,
|
||||
method='filter_booking_status',
|
||||
)
|
||||
self.filters['booking-status'].parent = self
|
||||
|
||||
def filter_booking_status(self, queryset, name, value):
|
||||
if value == 'not-booked':
|
||||
return queryset.none()
|
||||
if value == 'cancelled':
|
||||
return queryset.filter(cancellation_datetime__isnull=False)
|
||||
queryset = queryset.filter(cancellation_datetime__isnull=True)
|
||||
if value == 'booked':
|
||||
return queryset
|
||||
if value == 'not-checked':
|
||||
return queryset.filter(user_was_present__isnull=True)
|
||||
if value == 'presence':
|
||||
return queryset.filter(user_was_present=True)
|
||||
if value == 'absence':
|
||||
return queryset.filter(user_was_present=False)
|
||||
if value.startswith('absence-'):
|
||||
return queryset.filter(user_was_present=False, user_absence_reason=value[8:])
|
||||
return queryset
|
||||
|
||||
def do_nothing(self, queryset, name, value):
|
||||
return queryset
|
||||
|
||||
|
@ -365,6 +406,11 @@ class SubscriptionCheckFilterSet(BookingCheckFilterSet):
|
|||
model = Subscription
|
||||
fields = []
|
||||
|
||||
def filter_booking_status(self, queryset, name, value):
|
||||
if value != 'not-booked':
|
||||
return queryset.none()
|
||||
return queryset
|
||||
|
||||
|
||||
class BookingAbsenceReasonForm(forms.Form):
|
||||
reason = forms.ChoiceField(required=False)
|
||||
|
|
|
@ -1510,7 +1510,11 @@ def test_event_checked(app, admin_user):
|
|||
|
||||
|
||||
def test_event_check_filters(app, admin_user):
|
||||
agenda = Agenda.objects.create(label='Events', kind='events', booking_check_filters='foo,bar')
|
||||
group = AbsenceReasonGroup.objects.create(label='Foo bar')
|
||||
reason = AbsenceReason.objects.create(label='Foo reason', group=group)
|
||||
agenda = Agenda.objects.create(
|
||||
label='Events', kind='events', booking_check_filters='foo,bar', absence_reasons_group=group
|
||||
)
|
||||
event = Event.objects.create(
|
||||
label='xyz',
|
||||
start_datetime=now() - datetime.timedelta(days=1),
|
||||
|
@ -1531,29 +1535,43 @@ def test_event_check_filters(app, admin_user):
|
|||
event=event,
|
||||
user_external_id='user:1',
|
||||
user_first_name='User',
|
||||
user_last_name='foo-val1 bar-none',
|
||||
user_last_name='foo-val1 bar-none presence',
|
||||
extra_data={'foo': 'val1'},
|
||||
user_was_present=True,
|
||||
)
|
||||
Booking.objects.create(
|
||||
event=event,
|
||||
user_external_id='user:2',
|
||||
user_first_name='User',
|
||||
user_last_name='foo-val2 bar-val1',
|
||||
user_last_name='foo-val2 bar-val1 absence',
|
||||
extra_data={'foo': 'val2', 'bar': 'val1'},
|
||||
user_was_present=False,
|
||||
)
|
||||
Booking.objects.create(
|
||||
event=event,
|
||||
user_external_id='user:3',
|
||||
user_first_name='User',
|
||||
user_last_name='foo-val1 bar-val2',
|
||||
user_last_name='foo-val1 bar-val2 not-checked',
|
||||
extra_data={'foo': 'val1', 'bar': 'val2'},
|
||||
)
|
||||
Booking.objects.create(
|
||||
event=event,
|
||||
user_external_id='user:4',
|
||||
user_first_name='User',
|
||||
user_last_name='foo-none bar-val2',
|
||||
user_last_name='foo-none bar-val2 reason-foo',
|
||||
extra_data={'bar': 'val2'},
|
||||
user_was_present=False,
|
||||
user_absence_reason=reason.label,
|
||||
)
|
||||
Booking.objects.create(
|
||||
event=event,
|
||||
user_external_id='user:5',
|
||||
user_first_name='User',
|
||||
user_last_name='foo-none bar-val2 cancelled',
|
||||
extra_data={'bar': 'val2'},
|
||||
user_was_present=False,
|
||||
user_absence_reason=reason.label,
|
||||
cancellation_datetime=now(),
|
||||
)
|
||||
|
||||
Subscription.objects.create(
|
||||
|
@ -1611,57 +1629,37 @@ def test_event_check_filters(app, admin_user):
|
|||
)
|
||||
login(app)
|
||||
|
||||
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk))
|
||||
assert 'User none' in resp
|
||||
assert 'User empty' in resp
|
||||
assert 'User foo-val1 bar-none' in resp
|
||||
assert 'User foo-val2 bar-val1' in resp
|
||||
assert 'User foo-val1 bar-val2' in resp
|
||||
assert 'User foo-none bar-val2' in resp
|
||||
assert 'Subscription none' in resp
|
||||
assert 'Subscription empty' in resp
|
||||
assert 'Subscription foo-val1 bar-none' in resp
|
||||
assert 'Subscription foo-val2 bar-val1' in resp
|
||||
assert 'Subscription foo-val1 bar-val2' in resp
|
||||
assert 'Subscription foo-none bar-val2' in resp
|
||||
for params in [
|
||||
{},
|
||||
{'unknown': 'unknown'},
|
||||
{'extra-data-unknown': 'unknown'},
|
||||
{'extra-data-foo': 'unknown'},
|
||||
]:
|
||||
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params=params)
|
||||
assert 'User none' in resp
|
||||
assert 'User empty' in resp
|
||||
assert 'User foo-val1 bar-none presence' in resp
|
||||
assert 'User foo-val2 bar-val1 absence' in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' in resp
|
||||
assert 'User foo-none bar-val2 cancelled' in resp
|
||||
assert 'Subscription none' in resp
|
||||
assert 'Subscription empty' in resp
|
||||
assert 'Subscription foo-val1 bar-none' in resp
|
||||
assert 'Subscription foo-val2 bar-val1' in resp
|
||||
assert 'Subscription foo-val1 bar-val2' in resp
|
||||
assert 'Subscription foo-none bar-val2' in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'unknown': 'unknown'}
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'extra-data-foo': 'val1'}
|
||||
)
|
||||
assert 'User none' in resp
|
||||
assert 'User empty' in resp
|
||||
assert 'User foo-val1 bar-none' in resp
|
||||
assert 'User foo-val2 bar-val1' in resp
|
||||
assert 'User foo-val1 bar-val2' in resp
|
||||
assert 'User foo-none bar-val2' in resp
|
||||
assert 'Subscription none' in resp
|
||||
assert 'Subscription empty' in resp
|
||||
assert 'Subscription foo-val1 bar-none' in resp
|
||||
assert 'Subscription foo-val2 bar-val1' in resp
|
||||
assert 'Subscription foo-val1 bar-val2' in resp
|
||||
assert 'Subscription foo-none bar-val2' in resp
|
||||
|
||||
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'foo': 'unknown'})
|
||||
assert 'User none' in resp
|
||||
assert 'User empty' in resp
|
||||
assert 'User foo-val1 bar-none' in resp
|
||||
assert 'User foo-val2 bar-val1' in resp
|
||||
assert 'User foo-val1 bar-val2' in resp
|
||||
assert 'User foo-none bar-val2' in resp
|
||||
assert 'Subscription none' in resp
|
||||
assert 'Subscription empty' in resp
|
||||
assert 'Subscription foo-val1 bar-none' in resp
|
||||
assert 'Subscription foo-val2 bar-val1' in resp
|
||||
assert 'Subscription foo-val1 bar-val2' in resp
|
||||
assert 'Subscription foo-none bar-val2' in resp
|
||||
|
||||
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'foo': 'val1'})
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none' in resp
|
||||
assert 'User foo-val2 bar-val1' not in resp
|
||||
assert 'User foo-val1 bar-val2' in resp
|
||||
assert 'User foo-none bar-val2' not in resp
|
||||
assert 'User foo-val1 bar-none presence' in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' in resp
|
||||
|
@ -1670,14 +1668,16 @@ def test_event_check_filters(app, admin_user):
|
|||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'foo': 'val1', 'bar': 'val2'}
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk),
|
||||
params={'extra-data-foo': 'val1', 'extra-data-bar': 'val2'},
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none' not in resp
|
||||
assert 'User foo-val2 bar-val1' not in resp
|
||||
assert 'User foo-val1 bar-val2' in resp
|
||||
assert 'User foo-none bar-val2' not in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
|
@ -1686,14 +1686,136 @@ def test_event_check_filters(app, admin_user):
|
|||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'foo': 'val2', 'bar': 'val2'}
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk),
|
||||
params={'extra-data-foo': 'val2', 'extra-data-bar': 'val2'},
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none' not in resp
|
||||
assert 'User foo-val2 bar-val1' not in resp
|
||||
assert 'User foo-val1 bar-val2' not in resp
|
||||
assert 'User foo-none bar-val2' not in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' not in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
assert 'Subscription foo-val2 bar-val1' not in resp
|
||||
assert 'Subscription foo-val1 bar-val2' not in resp
|
||||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'booking-status': 'booked'}
|
||||
)
|
||||
assert 'User none' in resp
|
||||
assert 'User empty' in resp
|
||||
assert 'User foo-val1 bar-none presence' in resp
|
||||
assert 'User foo-val2 bar-val1 absence' in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
assert 'Subscription foo-val2 bar-val1' not in resp
|
||||
assert 'Subscription foo-val1 bar-val2' not in resp
|
||||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'booking-status': 'not-booked'}
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' not in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' in resp
|
||||
assert 'Subscription empty' in resp
|
||||
assert 'Subscription foo-val1 bar-none' in resp
|
||||
assert 'Subscription foo-val2 bar-val1' in resp
|
||||
assert 'Subscription foo-val1 bar-val2' in resp
|
||||
assert 'Subscription foo-none bar-val2' in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'booking-status': 'cancelled'}
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' not in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
assert 'Subscription foo-val2 bar-val1' not in resp
|
||||
assert 'Subscription foo-val1 bar-val2' not in resp
|
||||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'booking-status': 'not-checked'}
|
||||
)
|
||||
assert 'User none' in resp
|
||||
assert 'User empty' in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
assert 'Subscription foo-val2 bar-val1' not in resp
|
||||
assert 'Subscription foo-val1 bar-val2' not in resp
|
||||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'booking-status': 'presence'}
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none presence' in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' not in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' not in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
assert 'Subscription foo-val2 bar-val1' not in resp
|
||||
assert 'Subscription foo-val1 bar-val2' not in resp
|
||||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk), params={'booking-status': 'absence'}
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' not in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
assert 'Subscription foo-val2 bar-val1' not in resp
|
||||
assert 'Subscription foo-val1 bar-val2' not in resp
|
||||
assert 'Subscription foo-none bar-val2' not in resp
|
||||
|
||||
resp = app.get(
|
||||
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk),
|
||||
params={'booking-status': 'absence-Foo reason'},
|
||||
)
|
||||
assert 'User none' not in resp
|
||||
assert 'User empty' not in resp
|
||||
assert 'User foo-val1 bar-none presence' not in resp
|
||||
assert 'User foo-val2 bar-val1 absence' not in resp
|
||||
assert 'User foo-val1 bar-val2 not-checked' not in resp
|
||||
assert 'User foo-none bar-val2 reason-foo' in resp
|
||||
assert 'User foo-none bar-val2 cancelled' not in resp
|
||||
assert 'Subscription none' not in resp
|
||||
assert 'Subscription empty' not in resp
|
||||
assert 'Subscription foo-val1 bar-none' not in resp
|
||||
|
|
Loading…
Reference in New Issue