Commit 4b2bd3b1 authored by Willem ter Berg's avatar Willem ter Berg

added date_planned validation, now mandatory when status is gepland or in onderzoek

parent 670df7cd
......@@ -42,6 +42,7 @@ def create_schema(schema):
are_uris = tk.get_validator('are_uris')
spatial_validation = tk.get_validator('spatial_validation')
temporal_validation = tk.get_validator('temporal_validation')
date_planned_validation = tk.get_validator('date_planned_validation')
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')
......@@ -91,7 +92,11 @@ def create_schema(schema):
'sample': [optional, are_uris, to_extras],
'dataset_status': [recommended, overheid_dataset_status, to_extras],
'date_planned': [optional, is_date, to_extras],
'__after': [spatial_validation, temporal_validation, contact_point_validation, legal_foundation_validation]
'__after': [spatial_validation,
temporal_validation,
contact_point_validation,
legal_foundation_validation,
date_planned_validation]
})
schema['resources'].update({
......@@ -156,6 +161,7 @@ def update_schema(schema):
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')
date_planned_validation = tk.get_validator('date_planned_validation')
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')
......@@ -204,7 +210,11 @@ def update_schema(schema):
'sample': [optional, to_list_if_curly_string, are_uris, to_extras],
'dataset_status': [recommended, overheid_dataset_status, to_extras],
'date_planned': [optional, is_date, to_extras],
'__after': [spatial_validation, temporal_validation, contact_point_validation, legal_foundation_validation]
'__after': [spatial_validation,
temporal_validation,
contact_point_validation,
legal_foundation_validation,
date_planned_validation]
})
schema['resources'].update({
......
......@@ -58,3 +58,30 @@ def valid_temporal(key, data, errors, context):
errors[('temporal_end',)].append('temporal_end cannot be smaller or equal to temporal_start')
return key, data, errors, context
def date_planned_validation(key, data_dict, errors, context):
"""
Enforces that date_planned becomes mandatory when dataset_status has a value of either '' or ''.
:param key: str, argument to match CKAN method signature, not used
:param data: dict, flattened dict of the dataset
:param errors: dict, flattened dict of the validation errors
:param context: dict, argument to match CKAN method signature, not used
:return: (key, data, errors, context), the original arguments, possibly modified
"""
dataset_status_tuple = ('dataset_status',)
affected_statusses = [
'http://data.overheid.nl/status/gepland',
'http://data.overheid.nl/status/in onderzoek'
]
if not dataset_status_tuple in data_dict:
return key, data_dict, errors, context
if data_dict[dataset_status_tuple] in affected_statusses:
if not ('date_planned') in data_dict:
errors[('date_planned',)] = ['date_planned is mandatory when dataset_status is gepland '
'or in onderzoek']
return key, data_dict, errors, context
......@@ -30,6 +30,7 @@ _VALIDATORS = {
'adms_changetype_updated': changetype_validator.changetype_updated,
'spatial_validation': spatial_validator.valid_spatial,
'temporal_validation': temporal_validator.valid_temporal,
'date_planned_validation': temporal_validator.date_planned_validation,
'contact_point_validation': contact_point_validator.valid_contact_point,
'hash_validation': hash_validator.valid_hash,
'legal_foundation_validation': legal_foundation_validator.valid_legal_foundation,
......
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