Commit db674901 authored by Willem ter Berg's avatar Willem ter Berg

Modified spatial validation to expect a 1 to 1 list of schemes and values

parent d91949ef
......@@ -64,19 +64,18 @@ def valid_spatial(key, data, errors, context):
schemes = data[('spatial_scheme',)]
values = data[('spatial_value',)]
for val in values:
is_valid = False
if len(schemes) != len(values):
errors[('spatial_value',)].append('The amount of spatial_schemes does not correspond with '
'the amount of spatial_values')
errors[('spatial_scheme',)].append('The amount of spatial_schemes does not correspond with '
'the amount of spatial_values')
for scheme in schemes:
validator_name = _get_validator_for_spatial_scheme(scheme)
validates = validator_factory.get_validator(validator_name)
if validates(val):
is_valid = True
return key, data, errors, context
if not is_valid:
for iterator, val in enumerate(values):
if not validator_factory.get_validator(_get_validator_for_spatial_scheme(schemes[iterator]))(val):
errors[('spatial_value',)].append('value [' + val + '] is not a valid spatial according'
' to the schemes provided')
' to the scheme provided')
return key, data, errors, context
......
......@@ -81,7 +81,7 @@ def overheid_spatial_scheme(value):
:param value: str, the value to validate
:return: str, the original value if it passes validation
"""
return _check_values('overheid_spatial_scheme', value, 1, 0)
return _check_values('overheid_spatial_scheme', value, 1, 0, False)
def overheid_spatial_gemeente(value):
......@@ -252,7 +252,7 @@ def _check_value(name, value):
return value
def _check_values(name, values, minimum=1, maximum=0):
def _check_values(name, values, minimum=1, maximum=0, unique_check=True):
"""
Checks a given list of values against the given valuelist. Raises an
ckan.plugins.toolkit.Invalid if the values do not pass the validation.
......@@ -272,8 +272,9 @@ def _check_values(name, values, minimum=1, maximum=0):
if 0 < maximum < len(values):
raise tk.Invalid('values do not meet the maximum requirements')
if not len(values) == len(set(values)):
raise tk.Invalid('values must be unique')
if unique_check:
if not len(values) == len(set(values)):
raise tk.Invalid('values must be unique')
valid_values = _read_file_as_json(name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment