Skip to content

Commit

Permalink
fix: use ckan string validators
Browse files Browse the repository at this point in the history
Can't use str anymore in CKAN 2.10, so using unicode_safe instead. Additionally, switching from ckantools list_of_strings to the CKAN one.
  • Loading branch information
jrdh committed Sep 13, 2023
1 parent 6629dbf commit 581962b
Showing 1 changed file with 57 additions and 54 deletions.
111 changes: 57 additions & 54 deletions ckanext/attribution/logic/actions/meta/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# This file is part of ckanext-attribution
# Created by the Natural History Museum in London, UK

from ckantools.validators import list_of_strings

from ckan.plugins import toolkit

# grab all the validator functions upfront
Expand All @@ -14,124 +12,129 @@
boolean_validator = toolkit.get_validator('boolean_validator')
isodate_validator = toolkit.get_validator('isodate')
int_validator = toolkit.get_validator('int_validator')
unicode_safe = toolkit.get_validator("unicode_safe")
list_of_strings = toolkit.get_validator("list_of_strings")

# CREATE ===========================================================================================

agent_affiliation_create = {
'agent_a_id': [not_missing, str],
'agent_b_id': [not_missing, str],
'affiliation_type': [ignore_missing, str],
'description': [ignore_missing, str],
'agent_a_id': [not_missing, unicode_safe],
'agent_b_id': [not_missing, unicode_safe],
'affiliation_type': [ignore_missing, unicode_safe],
'description': [ignore_missing, unicode_safe],
'start_date': [ignore_missing, isodate_validator],
'end_date': [ignore_missing, isodate_validator],
}

agent_create = {
'agent_type': [not_missing, str],
'family_name': [ignore_missing, str],
'given_names': [ignore_missing, str],
'agent_type': [not_missing, unicode_safe],
'family_name': [ignore_missing, unicode_safe],
'given_names': [ignore_missing, unicode_safe],
'given_names_first': [ignore_missing, boolean_validator],
'user_id': [ignore_missing, str],
'name': [ignore_missing, str],
'user_id': [ignore_missing, unicode_safe],
'name': [ignore_missing, unicode_safe],
}

contribution_activity_create = {
'package_id': [not_missing, str],
'agent_id': [not_missing, str],
'activity': [not_missing, str],
'scheme': [not_missing, str],
'level': [ignore_missing, str],
'package_id': [not_missing, unicode_safe],
'agent_id': [not_missing, unicode_safe],
'activity': [not_missing, unicode_safe],
'scheme': [not_missing, unicode_safe],
'level': [ignore_missing, unicode_safe],
'time': [ignore_missing, isodate_validator],
}

# DELETE ===========================================================================================

agent_affiliation_delete = {'id': [not_missing, str]}
agent_affiliation_delete = {'id': [not_missing, unicode_safe]}

agent_delete = {'id': [not_missing, str]}
agent_delete = {'id': [not_missing, unicode_safe]}

agent_contribution_activity_delete = {'id': [not_missing, str]}
agent_contribution_activity_delete = {'id': [not_missing, unicode_safe]}

contribution_activity_delete = {
'id': [not_missing, str],
'id': [not_missing, unicode_safe],
}

package_contribution_activity_delete = {'id': [not_missing, str]}
package_contribution_activity_delete = {'id': [not_missing, unicode_safe]}

# EXTRA ============================================================================================

attribution_controlled_lists = {'lists': [ignore_missing, list_of_strings()]}
attribution_controlled_lists = {'lists': [ignore_missing, list_of_strings]}

agent_external_search = {
'q': [not_missing, str],
'sources': [ignore_missing, list_of_strings()],
'q': [not_missing, unicode_safe],
'sources': [ignore_missing, list_of_strings],
}

agent_external_read = {
'agent_id': [ignore_missing, str],
'external_id': [ignore_missing, str],
'external_id_scheme': [ignore_missing, str],
'agent_id': [ignore_missing, unicode_safe],
'external_id': [ignore_missing, unicode_safe],
'external_id_scheme': [ignore_missing, unicode_safe],
'diff': [ignore_missing, boolean_validator],
}

validate_external_id = {
'external_id': [not_missing, str],
'external_id_scheme': [not_missing, str],
'external_id': [not_missing, unicode_safe],
'external_id_scheme': [not_missing, unicode_safe],
}

# SHOW =============================================================================================

agent_affiliation_show = {'id': [not_missing, str]}
agent_affiliation_show = {'id': [not_missing, unicode_safe]}

agent_show = {'id': [not_missing, str]}
agent_show = {'id': [not_missing, unicode_safe]}

agent_list = {'q': [ignore_missing, str], 'mode': [ignore_missing, str]}
agent_list = {
'q': [ignore_missing, unicode_safe],
'mode': [ignore_missing, unicode_safe],
}

agent_contribution_activity_show = {'id': [not_missing, str]}
agent_contribution_activity_show = {'id': [not_missing, unicode_safe]}

contribution_activity_show = {'id': [not_missing, str]}
contribution_activity_show = {'id': [not_missing, unicode_safe]}

package_contribution_activity_show = {'id': [not_missing, str]}
package_contribution_activity_show = {'id': [not_missing, unicode_safe]}

package_contributions_show = {
'id': [not_missing, str],
'id': [not_missing, unicode_safe],
'limit': [ignore_missing, int_validator],
'offset': [ignore_missing, int_validator],
}

agent_affiliations = {
'agent_id': [not_missing, str],
'package_id': [ignore_missing, str],
'agent_id': [not_missing, unicode_safe],
'package_id': [ignore_missing, unicode_safe],
}

# UPDATE ===========================================================================================

agent_affiliation_update = {
'id': [not_missing, str],
'agent_a_id': [ignore_missing, str],
'agent_b_id': [ignore_missing, str],
'affiliation_type': [ignore_missing, str],
'description': [ignore_missing, str],
'id': [not_missing, unicode_safe],
'agent_a_id': [ignore_missing, unicode_safe],
'agent_b_id': [ignore_missing, unicode_safe],
'affiliation_type': [ignore_missing, unicode_safe],
'description': [ignore_missing, unicode_safe],
'start_date': [ignore_missing, isodate_validator],
'end_date': [ignore_missing, isodate_validator],
}

agent_update = {
'id': [not_missing, str],
'agent_type': [ignore_missing, str],
'family_name': [ignore_missing, str],
'given_names': [ignore_missing, str],
'id': [not_missing, unicode_safe],
'agent_type': [ignore_missing, unicode_safe],
'family_name': [ignore_missing, unicode_safe],
'given_names': [ignore_missing, unicode_safe],
'given_names_first': [ignore_missing, boolean_validator],
'user_id': [ignore_missing, str],
'name': [ignore_missing, str],
'user_id': [ignore_missing, unicode_safe],
'name': [ignore_missing, unicode_safe],
}

agent_external_update = {'id': [not_missing, str]}
agent_external_update = {'id': [not_missing, unicode_safe]}

contribution_activity_update = {
'id': [not_missing, str],
'activity': [ignore_missing, str],
'scheme': [ignore_missing, str],
'level': [ignore_missing, str],
'id': [not_missing, unicode_safe],
'activity': [ignore_missing, unicode_safe],
'scheme': [ignore_missing, unicode_safe],
'level': [ignore_missing, unicode_safe],
'time': [ignore_missing, isodate_validator],
}

0 comments on commit 581962b

Please sign in to comment.