Commit 2da02c57 authored by Willem ter Berg's avatar Willem ter Berg

added multivalues for resource

parent 9f2776bb
......@@ -45,6 +45,7 @@ def create_schema(schema):
contact_point_validation = tk.get_validator('contact_point_validation')
hash_validation = tk.get_validator('hash_validation')
legal_foundation_validation = tk.get_validator('legal_foundation_validation')
to_curly_string_if_list = tk.get_converter('convert_to_curly_string_if_list')
schema.update({
'identifier': [mandatory, is_string, to_extras],
......@@ -98,20 +99,20 @@ def create_schema(schema):
'name': [mandatory, is_string],
'description': [mandatory, is_string],
'metadata_language': [mandatory, donl_language],
'language': [mandatory, donl_language],
'language': [mandatory, donl_languages, to_curly_string_if_list],
'license': [mandatory, overheid_license],
'format': [mandatory, mdr_filetype_nal],
'size': [recommended, is_number],
'download_url': [recommended, is_uri],
'download_url': [recommended, are_uris, to_curly_string_if_list],
'mimetype': [recommended, iana_mediatypes],
'release_date': [recommended, is_date],
'rights': [recommended, is_string],
'status': [recommended, adms_distributiestatus],
'modification_date': [recommended, is_date],
'linked_schemas': [recommended, is_string],
'linked_schemas': [recommended, is_list, to_curly_string_if_list],
'hash': [optional, is_string],
'hash_algorithm': [optional, is_string],
'documentation': [optional, is_uri],
'documentation': [optional, are_uris, to_curly_string_if_list],
'__after': [hash_validation]
})
......@@ -152,6 +153,7 @@ def update_schema(schema):
is_list = tk.get_validator('is_list')
are_uris = tk.get_validator('are_uris')
to_list_if_curly_string = tk.get_converter('convert_to_list_if_curly_string')
to_curly_string_if_list = tk.get_converter('convert_to_curly_string_if_list')
spatial_validation = tk.get_validator('spatial_validation')
temporal_validation = tk.get_validator('temporal_validation')
contact_point_validation = tk.get_validator('contact_point_validation')
......@@ -210,20 +212,20 @@ def update_schema(schema):
'name': [mandatory, is_string],
'description': [mandatory, is_string],
'metadata_language': [mandatory, donl_language],
'language': [mandatory, donl_language],
'language': [mandatory, donl_languages, to_curly_string_if_list],
'license': [mandatory, overheid_license],
'format': [mandatory, mdr_filetype_nal],
'size': [recommended, is_number],
'download_url': [recommended, is_uri],
'download_url': [recommended, are_uris, to_curly_string_if_list],
'mimetype': [recommended, iana_mediatypes],
'release_date': [recommended, is_date],
'rights': [recommended, is_string],
'status': [recommended, adms_distributiestatus],
'modification_date': [recommended, is_date],
'linked_schemas': [recommended, is_string],
'linked_schemas': [recommended, is_list, to_curly_string_if_list],
'hash': [optional, is_string],
'hash_algorithm': [optional, is_string],
'documentation': [optional, is_uri],
'documentation': [optional, are_uris, to_curly_string_if_list],
'__after': [hash_validation]
})
......@@ -294,20 +296,20 @@ def show_schema(schema):
'name': [mandatory],
'description': [mandatory],
'metadata_language': [mandatory],
'language': [mandatory],
'language': [mandatory, to_list_if_curly_string],
'license': [mandatory],
'format': [mandatory],
'size': [recommended],
'download_url': [recommended],
'download_url': [recommended, to_list_if_curly_string],
'mimetype': [recommended],
'release_date': [recommended],
'rights': [recommended],
'status': [recommended],
'modification_date': [recommended],
'linked_schemas': [recommended],
'linked_schemas': [recommended, to_list_if_curly_string],
'hash': [optional],
'hash_algorithm': [optional],
'documentation': [optional]
'documentation': [optional, to_list_if_curly_string]
})
return schema
......@@ -66,3 +66,20 @@ def convert_to_list_if_string(key, data_dict, errors, context):
data_dict[key] = values[1:len(values) - 1].split(',')
return key, data_dict, errors, context
def convert_to_curly_string_if_list(key, data_dict, errors, context):
"""
Converts a list of strings to a string surrounded with curly braces.
:param key: str, the key of the data_dict dictionary
:param data_dict: dict, the dictionary to modify
:param errors: dict, argument to match CKAN method signature, not used
:param context: dict, argument to match CKAN method signature, not used
:return: (key, data, errors, context), the original arguments, possibly modified
"""
values = data_dict[key]
if isinstance(values, list):
data_dict[key] = '{' + ','.join(map(str, values)) + '}'
return key, data_dict, errors, context
......@@ -52,7 +52,8 @@ _VALIDATORS = {
'mdr_filetype_nal': valuelist_validator.mdr_filetype_nal,
'iana_mediatypes': valuelist_validator.iana_mediatypes,
'adms_distributiestatus': valuelist_validator.adms_distributiestatus,
'convert_to_list_if_curly_string': type_validator.convert_to_list_if_string
'convert_to_list_if_curly_string': type_validator.convert_to_list_if_string,
'convert_to_curly_string_if_list': type_validator.convert_to_curly_string_if_list
}
......
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