0001-datasources-avoid-raising-on-lost-datasource-18431.patch
tests/test_form_pages.py | ||
---|---|---|
4238 | 4238 |
resp = resp.forms[0].submit('submit') |
4239 | 4239 |
assert 'Check values then click submit.' in resp.body |
4240 | 4240 | |
4241 |
def test_unknown_datasource(pub): |
|
4242 |
formdef = create_formdef() |
|
4243 |
formdef.fields = [ |
|
4244 |
fields.StringField(id='1', label='string', |
|
4245 |
varname='string', required=False, data_source={'type': 'foobar'}), |
|
4246 |
fields.ItemField(id='2', label='item', |
|
4247 |
varname='item', required=False, data_source={'type': 'foobar'}), |
|
4248 |
fields.ItemsField(id='3', label='items', |
|
4249 |
varname='items', required=False, data_source={'type': 'foobar'}), |
|
4250 |
] |
|
4251 | ||
4252 |
formdef.store() |
|
4253 |
data_class = formdef.data_class() |
|
4254 |
data_class.wipe() |
|
4255 |
resp = get_app(pub).get('/test/') |
|
4256 |
formdef.data_class().wipe() |
|
4257 |
resp = resp.forms[0].submit('submit') # should go straight to validation |
|
4258 |
assert 'Check values then click submit.' in resp.body |
|
4259 | ||
4241 | 4260 |
def test_form_items_datasource(pub): |
4242 | 4261 |
formdef = create_formdef() |
4243 | 4262 |
formdef.fields = [fields.ItemsField(id='1', label='items', |
wcs/data_sources.py | ||
---|---|---|
102 | 102 | |
103 | 103 | |
104 | 104 |
def get_items(data_source, include_disabled=False, mode=None): |
105 |
structured_items = get_structured_items(data_source, mode=mode) |
|
105 |
structured_items = get_structured_items(data_source, mode=mode) or []
|
|
106 | 106 |
tupled_items = [] |
107 | 107 |
for item in structured_items: |
108 | 108 |
if item.get('disabled') and not include_disabled: |
... | ... | |
130 | 130 |
if data_source.get('type') not in ('json', 'jsonp', 'formula'): |
131 | 131 |
# named data source |
132 | 132 |
named_data_source = NamedDataSource.get_by_slug(data_source['type']) |
133 |
if not named_data_source: |
|
134 |
return |
|
133 | 135 |
if named_data_source.cache_duration: |
134 | 136 |
cache_duration = int(named_data_source.cache_duration) |
135 | 137 |
data_source = named_data_source.data_source |
... | ... | |
231 | 233 |
return data_source |
232 | 234 |
if ds_type and ds_type.startswith('carddef:'): |
233 | 235 |
return data_source |
234 |
return NamedDataSource.get_by_slug(ds_type).data_source |
|
236 |
named_data_source = NamedDataSource.get_by_slug(ds_type) |
|
237 |
return named_data_source.data_source if named_data_source else None |
|
235 | 238 | |
236 | 239 | |
237 | 240 |
def get_object(data_source): |
... | ... | |
330 | 333 |
objects = [x for x in cls.select() if x.slug == slug] |
331 | 334 |
if objects: |
332 | 335 |
return objects[0] |
333 |
raise KeyError("data source '%s' does not exist" % slug) |
|
336 |
get_logger().warn("data source '%s' does not exist" % slug) |
|
337 |
return None |
|
334 | 338 | |
335 | 339 |
def get_json_query_url(self): |
336 | 340 |
url = self.data_source.get('value').strip() |
... | ... | |
422 | 426 | |
423 | 427 |
class DataSourcesSubstitutionProxy(object): |
424 | 428 |
def __getattr__(self, attr): |
425 |
return get_structured_items(NamedDataSource.get_by_slug(attr).data_source) |
|
429 |
named_data_source = NamedDataSource.get_by_slug(attr) |
|
430 |
return get_structured_items(named_data_source.data_source) if named_data_source else [] |
wcs/fields.py | ||
---|---|---|
725 | 725 |
def perform_more_widget_changes(self, form, kwargs, edit=True): |
726 | 726 |
if self.data_source: |
727 | 727 |
real_data_source = data_sources.get_real(self.data_source) |
728 |
if not real_data_source: |
|
729 |
return |
|
728 | 730 |
if real_data_source.get('type') == 'jsonp': |
729 | 731 |
kwargs['url'] = real_data_source.get('value') |
730 | 732 |
self.widget_class = AutocompleteStringWidget |
wcs/formdef.py | ||
---|---|---|
668 | 668 |
live_condition_fields[varname].append(field) |
669 | 669 |
if field.key == 'item' and field.data_source: |
670 | 670 |
real_data_source = data_sources.get_real(field.data_source) |
671 |
if not real_data_source: |
|
672 |
continue |
|
671 | 673 |
if real_data_source.get('type') != 'json': |
672 | 674 |
continue |
673 | 675 |
varnames = field.get_referenced_varnames( |
... | ... | |
1010 | 1012 |
for field in formdef.fields: |
1011 | 1013 |
data_source = getattr(field, 'data_source', None) |
1012 | 1014 |
if data_source: |
1013 |
try: |
|
1014 |
data_sources.get_real(data_source) |
|
1015 |
except KeyError: |
|
1015 |
if not data_sources.get_real(data_source): |
|
1016 | 1016 |
unknown_datasources.add(data_source.get('type')) |
1017 | 1017 |
if unknown_datasources: |
1018 | 1018 |
raise FormdefImportError(N_('Unknown datasources'), |
wcs/forms/common.py | ||
---|---|---|
652 | 652 |
for field in displayed_fields: |
653 | 653 |
if field.key == 'item' and field.data_source: |
654 | 654 |
data_source = data_sources.get_object(field.data_source) |
655 |
if not data_source: |
|
656 |
continue |
|
655 | 657 |
if data_source.type != 'json': |
656 | 658 |
continue |
657 | 659 |
varnames = field.get_referenced_varnames( |
658 |
- |