api: only show presence filter for events agendas in statistics (#74327)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-02-16 11:33:49 +01:00 committed by Gitea
parent 331fdfa4a1
commit 518124ac1a
2 changed files with 16 additions and 3 deletions

View File

@ -3240,9 +3240,14 @@ class BookingsStatistics(APIView):
.values_list('extra_data_keys', flat=True)
)
group_by_options = [{'id': 'user_was_present', 'label': _('Presence/Absence')}] + [
{'id': x, 'label': x.capitalize()} for x in extra_data_keys
]
group_by_options = [{'id': x, 'label': x.capitalize()} for x in extra_data_keys]
if any(x.kind == 'events' for x in agendas):
group_by_options = [{'id': 'user_was_present', 'label': _('Presence/Absence')}] + group_by_options
if not group_by_options:
return []
return [
{
'id': 'group_by',

View File

@ -203,6 +203,14 @@ def test_statistics_bookings_subfilters_list(app, user):
resp = app.get(url + '?agenda=category:category-b')
assert len(resp.json['data']['subfilters'][0]['options']) == 1
Agenda.objects.create(label='Meetings', kind='meetings', category=category_b)
resp = app.get(url + '?agenda=meetings')
assert resp.json['data']['subfilters'] == []
resp = app.get(url + '?agenda=category:category-b')
assert len(resp.json['data']['subfilters'][0]['options']) == 1
resp = app.get(url + '?agenda=xxx', status=400)
assert resp.json['err_desc'] == 'No agendas found.'