diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 6e514cc96dca2d5e1acaaf0f57a2fae7d5aa0649..5356bcbed6773a32230c9b444141833645c25c7c 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -421,7 +421,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'key': [ toolkit.get_converter('known_spatial_uri'), toolkit.get_converter('validate_licenseAttributionByText'), - toolkit.get_converter('tpsh_convert_subjectID_to_subjectText'), ] }) schema.update( diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py index 1cddc5613d3d1adfd171c12865b471ec29e459ca..c9d41a2d3a8755885f871265ad6c0e3929769f69 100644 --- a/ckanext/odsh/validation.py +++ b/ckanext/odsh/validation.py @@ -268,8 +268,7 @@ def tag_string_convert(key, data, errors, context): tag_name_validator(tag, context) -def convert_subjectID_to_subjectText(key, data, errors, context): - subject_id = _extract_value(data, 'subject') +def _convert_subjectID_to_subjectText(subject_id, flattened_data): default_subject_mapping_file_path = '/usr/lib/ckan/default/src/ckanext-odsh/subject_mapping.json' subject_mapping_file_path = config.get( 'ckanext.odsh.subject_mapping_file_path', default_subject_mapping_file_path) @@ -299,21 +298,23 @@ def convert_subjectID_to_subjectText(key, data, errors, context): ) subject_text = "" - new_index = next_extra_index(data) - data[('extras', new_index, 'key')] = 'subject_text' - data[('extras', new_index, 'value')] = subject_text + new_index = next_extra_index(flattened_data) + flattened_data[('extras', new_index, 'key')] = 'subject_text' + flattened_data[('extras', new_index, 'value')] = subject_text + return flattened_data -def validate_subject(value): +def validate_subject(key, flattened_data, errors, context): + subject_id = flattened_data[key] require_subject = toolkit.asbool( config.get('ckanext.odsh.require_subject', True) ) if not require_subject: - return value - if not value: + flattened_data = _convert_subjectID_to_subjectText(subject_id, flattened_data) + return + if not subject_id: raise toolkit.Invalid(_('Subject must not be empty.')) - return value - + flattened_data = _convert_subjectID_to_subjectText(subject_id, flattened_data) def get_validators(): @@ -323,5 +324,4 @@ def get_validators(): 'odsh_validate_extras': validate_extras, 'validate_licenseAttributionByText': validate_licenseAttributionByText, 'tpsh_validate_subject': validate_subject, - 'tpsh_convert_subjectID_to_subjectText': convert_subjectID_to_subjectText, }