dataviz: do not override time_range if not specified (#62030)
This commit is contained in:
parent
e876fd6348
commit
02865103a9
|
@ -209,6 +209,10 @@ class ChartNgPartialForm(ChartFiltersMixin, forms.ModelForm):
|
|||
field.required = False
|
||||
|
||||
def clean(self):
|
||||
for field in self._meta.fields:
|
||||
if field not in self.data:
|
||||
self.cleaned_data[field] = self.initial[field]
|
||||
|
||||
for filter_ in self.instance.statistic.filters:
|
||||
if filter_['id'] in self.data:
|
||||
self.instance.filter_params[filter_['id']] = self.cleaned_data.get(filter_['id'])
|
||||
|
|
|
@ -2012,6 +2012,7 @@ def test_chart_filters_cell(new_api_statistics, app, admin_user, nocache):
|
|||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
@pytest.mark.freeze_time('2021-10-06')
|
||||
def test_chartng_cell_api_view_get_parameters(app, normal_user, new_api_statistics, nocache):
|
||||
page = Page.objects.create(title='One', slug='index')
|
||||
cell = ChartNgCell(page=page, order=1, placeholder='content')
|
||||
|
@ -2036,23 +2037,38 @@ def test_chartng_cell_api_view_get_parameters(app, normal_user, new_api_statisti
|
|||
assert 'time_interval=year' in request.url
|
||||
assert 'ou=default' in request.url
|
||||
|
||||
cell.time_range = 'range'
|
||||
cell.time_range_start = '2022-01-01'
|
||||
cell.save()
|
||||
|
||||
app.get(location)
|
||||
request = new_api_mock.call['requests'][3]
|
||||
assert 'start=2022-01-01' in request.url
|
||||
assert 'ou=default' in request.url
|
||||
|
||||
app.get(location + '?time_range=current-month')
|
||||
request = new_api_mock.call['requests'][4]
|
||||
assert 'start=2021-10-01' in request.url
|
||||
assert 'end=2021-11-01' in request.url
|
||||
assert 'ou=default' in request.url
|
||||
|
||||
cell.filter_params.clear()
|
||||
cell.statistic = Statistic.objects.get(slug='filter-multiple')
|
||||
cell.save()
|
||||
app.get(location + '?color=green&color=blue')
|
||||
request = new_api_mock.call['requests'][3]
|
||||
request = new_api_mock.call['requests'][5]
|
||||
assert 'color=green&color=blue' in request.url
|
||||
|
||||
# unknown params
|
||||
app.get(location + '?time_interval=month&ou=default')
|
||||
request = new_api_mock.call['requests'][4]
|
||||
request = new_api_mock.call['requests'][6]
|
||||
assert 'time_interval=' not in request.url
|
||||
assert 'ou=' not in request.url
|
||||
|
||||
# wrong params
|
||||
resp = app.get(location + '?time_range_start=xxx')
|
||||
assert 'Wrong parameters' in resp.text
|
||||
assert len(new_api_mock.call['requests']) == 5
|
||||
assert len(new_api_mock.call['requests']) == 7
|
||||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
|
|
Loading…
Reference in New Issue