Projet

Général

Profil

0001-forms-mark-unset-radio-options-as-disabled-in-readon.patch

Frédéric Péters, 12 juillet 2018 14:03

Télécharger (2,91 ko)

Voir les différences:

Subject: [PATCH] forms: mark unset radio options as disabled in readonly mode
 (#25246)

 tests/test_form_pages.py | 35 +++++++++++++++++++++++++++++++++++
 wcs/qommon/form.py       |  2 ++
 2 files changed, 37 insertions(+)
tests/test_form_pages.py
4356 4356
    assert not 'Check values then click submit.' in resp.body
4357 4357
    assert resp.form['f0'].value == 'foo@localhost'
4358 4358

  
4359
def test_form_page_profile_verified_radio_item_prefill(pub):
4360
    user = create_user(pub)
4361
    formdef = create_formdef()
4362
    formdef.data_class().wipe()
4363
    formdef.fields = [fields.ItemField(id='0', label='item', type='item',
4364
        items=['bar@localhost', 'foo@localhost', 'baz@localhost'],
4365
        show_as_radio=True,
4366
        prefill={'type': 'user', 'value': 'email'})]
4367
    formdef.store()
4368

  
4369
    resp = get_app(pub).get('/test/')
4370
    assert resp.form['f0'].value is None
4371

  
4372
    user.verified_fields = ['email']
4373
    user.store()
4374

  
4375
    resp = login(get_app(pub), username='foo', password='foo').get('/test/')
4376
    assert resp.form['f0'].value == 'foo@localhost'
4377
    assert 'readonly' in resp.form['f0'].attrs
4378
    for radio in resp.html.findAll('input'):
4379
        if radio['name'] == 'f0':
4380
            if radio['value'] == 'foo@localhost':
4381
                assert radio.attrs.get('checked')
4382
                assert radio.attrs.get('readonly')
4383
                assert not radio.attrs.get('disabled')
4384
            else:
4385
                assert not radio.attrs.get('checked')
4386
                assert radio.attrs.get('readonly')
4387
                assert radio.attrs.get('disabled')
4388

  
4389
    resp.form['f0'].value = 'baz@localhost' # try changing the value
4390
    resp = resp.form.submit('submit')
4391
    assert 'Check values then click submit.' in resp.body
4392
    assert resp.form['f0'].value == 'foo@localhost'  # it is reverted
4393

  
4359 4394
def test_item_field_with_disabled_items(http_requests, pub):
4360 4395
    user = create_user(pub)
4361 4396
    formdef = create_formdef()
wcs/qommon/form.py
207 207
            html_attrs = self.attrs.copy()
208 208
            if self.is_selected(object):
209 209
                html_attrs['checked'] = 'checked'
210
            elif self.attrs.get('readonly'):
211
                html_attrs['disabled'] = 'disabled'
210 212
            if self.options_with_attributes and option[-1].get('disabled'):
211 213
                html_attrs['disabled'] = 'disabled'
212 214
                label_tag = htmltext('<label class="disabled">')
213
-