Projet

Général

Profil

0001-forms-always-add-attributes-to-prefilled-fields-8223.patch

Frédéric Péters, 09 septembre 2015 13:43

Télécharger (3,03 ko)

Voir les différences:

Subject: [PATCH] forms: always add attributes to prefilled fields (#8223)

 tests/test_form_pages.py | 41 +++++++++++++++++++++++++++++++++++++++++
 wcs/forms/root.py        |  4 ++++
 2 files changed, 45 insertions(+)
tests/test_form_pages.py
1085 1085
    # go back to the status page, this will exercise the substitution variables
1086 1086
    # codepath.
1087 1087
    resp = resp.follow()
1088

  
1089
def test_form_map_field_back_and_submit(pub):
1090
    formdef = create_formdef()
1091
    formdef.fields = [
1092
        fields.MapField(id='0', label='map'),
1093
        fields.StringField(id='1', label='street', required=False,
1094
            prefill={'type': 'geolocation', 'value': 'road'}),
1095
    ]
1096
    formdef.store()
1097
    resp = get_app(pub).get('/test/')
1098
    formdef.data_class().wipe()
1099
    assert 'qommon.map.js' in resp.body
1100
    assert 'qommon.geolocation.js' in resp.body
1101
    # with a real user interaction this would get set by javascript
1102
    resp.forms[0]['f0$latlng'] = '1.234;-1.234'
1103
    assert 'data-geolocation="road"' in resp.body
1104

  
1105
    # check summary page
1106
    resp = resp.forms[0].submit('submit')
1107
    assert 'Check values then click submit.' in resp.body
1108
    assert 'data-init-lng="-1.234"' in resp.body
1109
    assert 'data-init-lat="1.234"' in resp.body
1110

  
1111
    # get back to the map field
1112
    resp = resp.forms[0].submit('previous')
1113
    # check the field is still marked as holding the road
1114
    assert 'data-geolocation="road"' in resp.body
1115
    assert resp.forms[0]['f0$latlng'].value == '1.234;-1.234'
1116

  
1117
    # back to summary page
1118
    resp = resp.forms[0].submit('submit')
1119

  
1120
    # and submitting the form
1121
    resp = resp.forms[0].submit('submit')
1122
    assert resp.status_int == 302
1123
    resp = resp.follow()
1124
    assert 'The form has been recorded' in resp.body
1125
    assert formdef.data_class().count() == 1
1126
    data_id = formdef.data_class().select()[0].id
1127
    data = formdef.data_class().get(data_id)
1128
    assert data.data == {'1': None, '0': '1.234;-1.234'}
wcs/forms/root.py
388 388
                        form.get_widget('f%s' % k).set_message(
389 389
                                _('Value has been automatically prefilled.'))
390 390
                        form.get_widget('f%s' % k).prefilled = True
391

  
392
                if field.prefill:
393
                    # always set additional attributes as they will be used for
394
                    # "live prefill", regardless of existing data.
391 395
                    form.get_widget('f%s' % k).prefill_attributes = field.get_prefill_attributes()
392 396

  
393 397
                if not prefilled and form.get_widget('f%s' % k):
394
-