admin: only allow geojson in named data sources (#45655)

This commit is contained in:
Frédéric Péters 2020-08-09 11:26:33 +02:00
parent 4a7ea75faa
commit 48cdfe3721
4 changed files with 12 additions and 6 deletions

View File

@ -81,6 +81,14 @@ def test_data_sources_new(pub):
resp = resp.click('New Data Source')
resp.forms[0]['name'] = 'a new data source'
resp.forms[0]['description'] = 'description of the data source'
assert resp.form['data_source$type'].options == [
('None', True, 'None'),
('json', False, 'JSON URL'),
('jsonp', False, 'JSONP URL'),
('geojson', False, 'GeoJSON URL'),
('python', False, 'Python Expression')
]
resp.forms[0]['data_source$type'] = 'python'
resp = resp.forms[0].submit('data_source$apply')
resp.forms[0]['data_source$value'] = repr(

View File

@ -1435,7 +1435,6 @@ def test_form_edit_item_field_data_source(pub):
(u'None', True, u'None'),
(u'json', False, u'JSON URL'),
(u'jsonp', False, u'JSONP URL'),
(u'geojson', False, u'GeoJSON URL'),
(u'python', False, u'Python Expression')
]
resp = resp.form.submit('submit').follow()
@ -1450,7 +1449,6 @@ def test_form_edit_item_field_data_source(pub):
(u'foobar', False, u'Foobar'),
(u'json', False, u'JSON URL'),
(u'jsonp', False, u'JSONP URL'),
(u'geojson', False, u'GeoJSON URL'),
(u'python', False, u'Python Expression')
]
resp.form['data_source$type'].value = 'foobar'
@ -1467,7 +1465,6 @@ def test_form_edit_item_field_data_source(pub):
(u'foobar', True, u'Foobar'),
(u'json', False, u'JSON URL'),
(u'jsonp', False, u'JSONP URL'),
(u'geojson', False, u'GeoJSON URL'),
(u'python', False, u'Python Expression')
]
@ -1481,7 +1478,6 @@ def test_form_edit_item_field_data_source(pub):
(u'foobar', True, u'Foobar'),
(u'json', False, u'JSON URL'),
(u'jsonp', False, u'JSONP URL'),
(u'geojson', False, u'GeoJSON URL'),
(u'python', False, u'Python Expression')
]

View File

@ -58,6 +58,7 @@ class NamedDataSourceUI(object):
form.add(DataSourceSelectionWidget, 'data_source',
value=self.datasource.data_source,
title=_('Data Source'),
allow_geojson=True,
allow_named_sources=False,
required=True)
form.add(DurationWidget, 'cache_duration',

View File

@ -52,7 +52,7 @@ def register_data_source_function(function, function_name=None):
class DataSourceSelectionWidget(CompositeWidget):
def __init__(self, name, value=None, allow_jsonp=True,
allow_named_sources=True, **kwargs):
allow_geojson=False, allow_named_sources=True, **kwargs):
CompositeWidget.__init__(self, name, value, **kwargs)
if not value:
@ -72,7 +72,8 @@ class DataSourceSelectionWidget(CompositeWidget):
options.append(('json', _('JSON URL'), 'json'))
if allow_jsonp:
options.append(('jsonp', _('JSONP URL'), 'jsonp'))
options.append(('geojson', _('GeoJSON URL'), 'geojson'))
if allow_geojson:
options.append(('geojson', _('GeoJSON URL'), 'geojson'))
options.append(('formula', _('Python Expression'), 'python'))
self.add(SingleSelectWidget, 'type', options=options, value=value.get('type'),