From e7f9a625df5ecf34744477febf162486e8730a7f Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 22 Feb 2024 12:01:11 +0100 Subject: [PATCH] statistics: always allow group by channel (#85530) --- tests/api/test_statistics.py | 11 +++++++++-- wcs/statistics/views.py | 11 +++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/api/test_statistics.py b/tests/api/test_statistics.py index 66ad9f8ea..d3734420d 100644 --- a/tests/api/test_statistics.py +++ b/tests/api/test_statistics.py @@ -991,6 +991,10 @@ def test_statistics_forms_count_group_by(pub, formdef, anonymise): {'data': [6, None, None], 'label': 'Backoffice'}, ] + # group by channel without form filter + new_resp = get_app(pub).get(sign_uri('/api/statistics/forms/count/?group-by=channel')) + assert new_resp.json['data']['series'] == resp.json['data']['series'] + # group by item field without time interval resp = get_app(pub).get(sign_uri(url + '&group-by=test-item&time_interval=none')) # Foo is first because it has a display value, baz is second because it has not, None is always last @@ -1100,7 +1104,10 @@ def test_statistics_forms_count_group_by_form(pub): assert resp.json['data']['subfilters'][1] == { 'id': 'group-by', 'label': 'Group by', - 'options': [{'id': 'form', 'label': 'Form'}], + 'options': [ + {'id': 'channel', 'label': 'Channel'}, + {'id': 'form', 'label': 'Form'}, + ], 'has_subfilters': True, } @@ -1726,8 +1733,8 @@ def test_statistics_multiple_forms_count_subfilters(pub, formdef): # group-by subfilter shows all common fields group_by_filter = [x for x in resp.json['data']['subfilters'] if x['id'] == 'group-by'][0] assert group_by_filter['options'] == [ - {'id': 'form', 'label': 'Form'}, {'id': 'channel', 'label': 'Channel'}, + {'id': 'form', 'label': 'Form'}, {'id': 'simple-status', 'label': 'Simplified status'}, {'id': 'test-item', 'label': 'Test item'}, {'id': 'checkbox', 'label': 'Checkbox'}, diff --git a/wcs/statistics/views.py b/wcs/statistics/views.py index 53a784863..99a267d46 100644 --- a/wcs/statistics/views.py +++ b/wcs/statistics/views.py @@ -383,7 +383,9 @@ class FormsCountView(RestrictedView): 'id': 'group-by', 'label': _('Group by'), 'has_subfilters': True, - 'options': [], + 'options': [ + {'id': 'channel', 'label': _('Channel')}, + ], } if len(formdefs) != 1: @@ -430,12 +432,9 @@ class FormsCountView(RestrictedView): subfilter['options'].sort(key=lambda x: x['label']) group_by_filter = [x for x in common_subfilters if x['id'] == 'group-by'][0] + group_by_filter['options'].append({'id': 'simple-status', 'label': _('Simplified status')}) group_by_filter['options'].extend( - [ - {'id': 'channel', 'label': _('Channel')}, - {'id': 'simple-status', 'label': _('Simplified status')}, - ] - + [{'id': x['id'].removeprefix('filter-'), 'label': x['label']} for x in subfilters] + [{'id': x['id'].removeprefix('filter-'), 'label': x['label']} for x in subfilters] ) if group_by not in (None, 'channel', 'simple-status', 'status'):