From 24b795caa9c80045fa227659a70e3884d30e857e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 14 Nov 2018 15:14:18 +0100 Subject: [PATCH] forms: use a template to render radio buttons (#27996) --- tests/test_form_pages.py | 4 +--- wcs/qommon/form.py | 37 ++++++++++--------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 64e88a812..7d5939e8e 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -4489,16 +4489,14 @@ def test_form_page_profile_verified_radio_item_prefill(pub): resp = login(get_app(pub), username='foo', password='foo').get('/test/') assert resp.form['f0'].value == 'foo@localhost' - assert 'readonly' in resp.form['f0'].attrs + assert 'disabled' in resp.form['f0'].attrs for radio in resp.html.findAll('input'): if radio['name'] == 'f0': if radio['value'] == 'foo@localhost': assert radio.attrs.get('checked') - assert radio.attrs.get('readonly') assert not radio.attrs.get('disabled') else: assert not radio.attrs.get('checked') - assert radio.attrs.get('readonly') assert radio.attrs.get('disabled') resp.form['f0'].value = 'baz@localhost' # try changing the value diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index d52bac878..81527515a 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -198,39 +198,22 @@ class SubmitWidget(quixote.form.widget.SubmitWidget): class RadiobuttonsWidget(quixote.form.RadiobuttonsWidget): + template_name = 'qommon/forms/widgets/radiobuttons.html' + def __init__(self, name, value=None, **kwargs): self.options_with_attributes = kwargs.pop('options_with_attributes', None) super(RadiobuttonsWidget, self).__init__(name, value=value, **kwargs) - def render_content(self): - include_disabled = False - options = self.options[:] - if self.options_with_attributes: - options = self.options_with_attributes - include_disabled = True - - r = TemplateIO(html=True) + def get_options(self): + options = self.options_with_attributes or self.options for i, option in enumerate(options): object, description, key = option[:3] - r += htmltext('