0001-fields-autocomplete-for-string-field-with-json-datas.patch
tests/test_form_pages.py | ||
---|---|---|
5176 | 5176 |
assert formdef.data_class().select()[0].data['3_display'] == 'barbar' |
5177 | 5177 | |
5178 | 5178 | |
5179 |
def test_form_string_field_autocomplete(pub): |
|
5179 |
@pytest.mark.parametrize('ds_type', ['jsonp', 'json']) |
|
5180 |
def test_form_string_field_autocomplete(pub, ds_type): |
|
5180 | 5181 |
formdef = create_formdef() |
5181 | 5182 |
formdef.fields = [fields.StringField(id='0', label='string', type='string', required=False)] |
5182 |
formdef.fields[0].data_source = {'type': 'jsonp'}
|
|
5183 |
formdef.fields[0].data_source = {'type': ds_type}
|
|
5183 | 5184 |
formdef.store() |
5184 | 5185 | |
5185 | 5186 |
# not filled completed, no call to .autocomplete |
... | ... | |
5187 | 5188 |
assert not ').autocomplete({' in resp.text |
5188 | 5189 | |
5189 | 5190 |
# straight URL |
5190 |
formdef.fields[0].data_source = {'type': 'jsonp', 'value': 'http://example.org'}
|
|
5191 |
formdef.fields[0].data_source = {'type': ds_type, 'value': 'http://example.org'}
|
|
5191 | 5192 |
formdef.store() |
5192 | 5193 |
resp = get_app(pub).get('/test/') |
5193 | 5194 |
assert ').autocomplete({' in resp.text |
5194 | 5195 |
assert 'http://example.org' in resp.text |
5195 | 5196 | |
5196 | 5197 |
# URL from variable |
5197 |
formdef.fields[0].data_source = {'type': 'jsonp', 'value': '[site_url]'}
|
|
5198 |
formdef.fields[0].data_source = {'type': ds_type, 'value': '[site_url]'}
|
|
5198 | 5199 |
formdef.store() |
5199 | 5200 |
resp = get_app(pub).get('/test/') |
5200 | 5201 |
assert ').autocomplete({' in resp.text |
wcs/fields.py | ||
---|---|---|
806 | 806 |
def perform_more_widget_changes(self, form, kwargs, edit=True): |
807 | 807 |
if self.data_source: |
808 | 808 |
real_data_source = data_sources.get_real(self.data_source) |
809 |
if real_data_source.get('type') == 'jsonp':
|
|
809 |
if real_data_source.get('type') in ['json', 'jsonp']:
|
|
810 | 810 |
kwargs['url'] = real_data_source.get('value') |
811 | 811 |
self.widget_class = AutocompleteStringWidget |
812 | 812 | |
813 |
- |