From df1614eae7f2f45ff6ad72252674c5f66fc287bb Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 8 Dec 2020 10:27:18 +0100 Subject: [PATCH 3/3] manager: allow dynamic fields in cell edit form (#49175) --- combo/manager/views.py | 1 + tests/test_dataviz.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/combo/manager/views.py b/combo/manager/views.py index a8cba24e..316d95e2 100644 --- a/combo/manager/views.py +++ b/combo/manager/views.py @@ -546,6 +546,7 @@ class PageEditCellView(UpdateView): def form_valid(self, form): if self.request.is_ajax(): self.object = form.save() + form = self.get_form_class()(instance=self.object) response = self.form_invalid(form) # avoid redirection else: response = super(PageEditCellView, self).form_valid(form) diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index b8c292c2..62f4cd46 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -973,6 +973,20 @@ def test_chartng_cell_manager_new_api(app, admin_user, new_api_statistics): assert cell.filter_params == {} +@with_httmock(new_api_mock) +def test_chartng_cell_manager_new_api_dynamic_fields(app, admin_user, new_api_statistics): + page = Page.objects.create(title='One', slug='index') + cell = ChartNgCell.objects.create(page=page, order=1, placeholder='content') + statistic = Statistic.objects.get(slug='one-serie') + + app = login(app) + resp = app.get('/manage/pages/%s/' % page.id) + field_prefix = 'cdataviz_chartngcell-%s-' % cell.id + resp.form[field_prefix + 'statistic'] = statistic.pk + resp = app.post(resp.form.action, params=resp.form.submit_fields(), xhr=True) + assert 'time_interval' in resp.text + + @with_httmock(bijoe_mock) def test_table_cell(app, admin_user, statistics): page = Page(title='One', slug='index') -- 2.20.1