From b2c02dd3bcf8d1d8fe77cb9c3d9ca32f86591724 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 5 Apr 2022 16:07:42 +0200 Subject: [PATCH] dataviz: hide time range field from filters cell if templates are used (#63397) --- combo/apps/dataviz/forms.py | 7 ++++++- tests/test_dataviz.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/combo/apps/dataviz/forms.py b/combo/apps/dataviz/forms.py index 84bf9a22..57eeb181 100644 --- a/combo/apps/dataviz/forms.py +++ b/combo/apps/dataviz/forms.py @@ -266,7 +266,12 @@ class ChartFiltersForm(ChartFiltersMixin, forms.ModelForm): self.fields[field].initial = getattr(first_cell, field) dynamic_fields = self.get_filter_fields(first_cell) dynamic_fields_values = {k: v for k, v in first_cell.filter_params.items()} - self.update_time_range_choices(first_cell.statistic, exclude_template_choice=True) + + if first_cell.time_range == 'range-template': + for field in self._meta.fields: + self.fields.pop(field, None) + else: + self.update_time_range_choices(first_cell.statistic, exclude_template_choice=True) for cell in chart_cells[1:]: cell_filter_fields = self.get_filter_fields(cell) diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index a1c9f8c7..03e963d9 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -2358,6 +2358,29 @@ def test_chart_filters_cell_future_data(app, admin_user, new_api_statistics): ] +@with_httmock(new_api_mock) +def test_chart_filters_cell_range_template(new_api_statistics, app, admin_user, nocache): + page = Page.objects.create(title='One', slug='index') + cell = ChartNgCell(page=page, order=1, placeholder='content') + cell.statistic = Statistic.objects.get(slug='one-serie') + cell.save() + ChartFiltersCell.objects.create(page=page, order=2, placeholder='content') + + app = login(app) + resp = app.get('/') + assert 'time_range' in resp.form.fields + assert 'time_range_start' in resp.form.fields + assert 'time_range_end' in resp.form.fields + + # if time range is set using templates, time range fields are hidden from filters + cell.time_range = 'range-template' + cell.save() + resp = app.get('/') + assert 'time_range' not in resp.form.fields + assert 'time_range_start' not in resp.form.fields + assert 'time_range_end' not in resp.form.fields + + @with_httmock(new_api_mock) def test_chart_filters_cell_with_subfilters(new_api_statistics, app, admin_user, nocache): page = Page.objects.create(title='One', slug='index') -- 2.30.2