From 0d6eb784e0eafce1ab9585ced802c157bea020f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 24 Jun 2022 16:23:33 +0200
Subject: [PATCH] manager: prefix ConfigJsonCell parameter fields in form
 (#66603)

---
 combo/data/forms.py   |  7 ++++---
 tests/test_manager.py | 32 ++++++++++++++++----------------
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/combo/data/forms.py b/combo/data/forms.py
index fb340651..ba5746c9 100644
--- a/combo/data/forms.py
+++ b/combo/data/forms.py
@@ -115,7 +115,7 @@ class ConfigJsonForm(forms.ModelForm):
         }
         for field in self.formdef:
             field_class = field_classes.get(field.get('type'), forms.CharField)
-            self.fields[field['varname']] = field_class(
+            self.fields['parameter_%s' % field['varname']] = field_class(
                 label=field['label'],
                 required=field.get('required', True),
                 initial=parameters.get(field['varname']),
@@ -125,7 +125,8 @@ class ConfigJsonForm(forms.ModelForm):
     def clean(self):
         self.cleaned_data['parameters'] = {}
         for field in self.formdef:
-            if field['varname'] not in self.cleaned_data:
+            varname = 'parameter_%s' % field['varname']
+            if varname not in self.cleaned_data:
                 continue
-            self.cleaned_data['parameters'][field['varname']] = self.cleaned_data[field['varname']]
+            self.cleaned_data['parameters'][field['varname']] = self.cleaned_data[varname]
         return self.cleaned_data
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 2a655adc..2272ef8a 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -1769,36 +1769,36 @@ def test_edit_config_json_cell(app, admin_user):
             'appearance',
         ]
 
-        resp.form['c%s-test' % cells[0].get_reference()].value = 'Hello world'
-        resp.form['c%s-test3' % cells[0].get_reference()].value = 'Hello again'
+        resp.form['c%s-parameter_test' % cells[0].get_reference()].value = 'Hello world'
+        resp.form['c%s-parameter_test3' % cells[0].get_reference()].value = 'Hello again'
         manager_submit_cell(resp.form)
 
         # test form error
         resp = app.get('/manage/pages/%s/' % page.id)
-        resp.form['c%s-test' % cells[0].get_reference()].value = ''
-        resp.form['c%s-test3' % cells[0].get_reference()].value = 'Hello'
+        resp.form['c%s-parameter_test' % cells[0].get_reference()].value = ''
+        resp.form['c%s-parameter_test3' % cells[0].get_reference()].value = 'Hello'
         resp = manager_submit_cell(resp.form, expect_errors=True)
-        assert resp.context['form'].errors['test'] == ['This field is required.']
+        assert resp.context['form'].errors['parameter_test'] == ['This field is required.']
 
         resp = app.get('/manage/pages/%s/' % page.id)
-        assert resp.form['c%s-test' % cells[0].get_reference()].value == 'Hello world'
-        assert resp.form['c%s-test2' % cells[0].get_reference()].checked is False
-        assert resp.form['c%s-test3' % cells[0].get_reference()].value == 'Hello again'
+        assert resp.form['c%s-parameter_test' % cells[0].get_reference()].value == 'Hello world'
+        assert resp.form['c%s-parameter_test2' % cells[0].get_reference()].checked is False
+        assert resp.form['c%s-parameter_test3' % cells[0].get_reference()].value == 'Hello again'
 
         resp = app.get('/manage/pages/%s/' % page.id)
         assert ('data-cell-reference="%s"' % cells[0].get_reference()) in resp.text
-        resp.forms[0]['c%s-test' % cells[0].get_reference()].value = 'World Hello'
-        resp.forms[0]['c%s-test2' % cells[0].get_reference()].checked = True
-        assert resp.form['c%s-test4' % cells[0].get_reference()].tag == 'textarea'
-        resp.forms[0]['c%s-test4' % cells[0].get_reference()].value = 'Text Area'
+        resp.forms[0]['c%s-parameter_test' % cells[0].get_reference()].value = 'World Hello'
+        resp.forms[0]['c%s-parameter_test2' % cells[0].get_reference()].checked = True
+        assert resp.form['c%s-parameter_test4' % cells[0].get_reference()].tag == 'textarea'
+        resp.forms[0]['c%s-parameter_test4' % cells[0].get_reference()].value = 'Text Area'
         resp = manager_submit_cell(resp.form)
         assert resp.json['tabs']['general']['form'].strip().startswith('<p><label')
 
         resp = app.get('/manage/pages/%s/' % page.id)
-        assert resp.form['c%s-test' % cells[0].get_reference()].value == 'World Hello'
-        assert resp.form['c%s-test2' % cells[0].get_reference()].checked is True
-        assert resp.form['c%s-test3' % cells[0].get_reference()].value == 'Hello again'
-        assert resp.form['c%s-test4' % cells[0].get_reference()].value == 'Text Area'
+        assert resp.form['c%s-parameter_test' % cells[0].get_reference()].value == 'World Hello'
+        assert resp.form['c%s-parameter_test2' % cells[0].get_reference()].checked is True
+        assert resp.form['c%s-parameter_test3' % cells[0].get_reference()].value == 'Hello again'
+        assert resp.form['c%s-parameter_test4' % cells[0].get_reference()].value == 'Text Area'
 
 
 def test_logout(app, admin_user):
-- 
2.35.1

