dataviz: set subfilter values in filters cell (#62227)
This commit is contained in:
parent
78394b3962
commit
8d5df537b5
|
@ -215,7 +215,7 @@ class ChartNgPartialForm(ChartFiltersMixin, forms.ModelForm):
|
|||
if field not in self.data:
|
||||
self.cleaned_data[field] = self.initial[field]
|
||||
|
||||
for filter_ in self.instance.statistic.filters:
|
||||
for filter_ in self.instance.available_filters:
|
||||
if filter_['id'] in self.data:
|
||||
self.instance.filter_params[filter_['id']] = self.cleaned_data.get(filter_['id'])
|
||||
|
||||
|
|
|
@ -2019,6 +2019,29 @@ def test_chart_filters_cell(new_api_statistics, app, admin_user, nocache):
|
|||
assert 'No filters are available' in resp.text
|
||||
|
||||
|
||||
@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')
|
||||
ChartFiltersCell.objects.create(page=page, order=1, placeholder='content')
|
||||
cell = ChartNgCell.objects.create(page=page, order=2, placeholder='content')
|
||||
cell.statistic = Statistic.objects.get(slug='with-subfilter')
|
||||
cell.save()
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/')
|
||||
assert 'form' in resp.form.fields
|
||||
assert 'menu' not in resp.form.fields
|
||||
|
||||
# select a choice with subfilters in manager
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
resp.forms[1]['cdataviz_chartngcell-%s-form' % cell.id] = 'food-request'
|
||||
resp = resp.forms[1].submit().follow()
|
||||
|
||||
resp = app.get('/')
|
||||
assert 'form' in resp.form.fields
|
||||
assert 'menu' in resp.form.fields
|
||||
|
||||
|
||||
@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):
|
||||
|
@ -2067,16 +2090,25 @@ def test_chartng_cell_api_view_get_parameters(app, normal_user, new_api_statisti
|
|||
request = new_api_mock.call['requests'][5]
|
||||
assert 'color=green&color=blue' in request.url
|
||||
|
||||
cell.filter_params.clear()
|
||||
cell.statistic = Statistic.objects.get(slug='with-subfilter')
|
||||
cell.filter_params = {'form': 'food-request'}
|
||||
cell.save()
|
||||
cell.update_subfilters()
|
||||
app.get(location + '?menu=vegan')
|
||||
request = new_api_mock.call['requests'][7]
|
||||
assert 'menu=vegan' in request.url
|
||||
|
||||
# unknown params
|
||||
app.get(location + '?time_interval=month&ou=default')
|
||||
request = new_api_mock.call['requests'][6]
|
||||
request = new_api_mock.call['requests'][8]
|
||||
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']) == 7
|
||||
assert len(new_api_mock.call['requests']) == 9
|
||||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
|
|
Loading…
Reference in New Issue