Validator functions reference

ckan.logic.validators.owner_org_validator(key, data, errors, context)
ckan.logic.validators.package_id_not_changed(value, context)
ckan.logic.validators.int_validator(value, context)

Return an integer for value, which may be a string in base 10 or a numeric type (e.g. int, long, float, Decimal, Fraction). Return None for None or empty/all-whitespace string values.

Raises:ckan.lib.navl.dictization_functions.Invalid for other inputs or non-whole values
ckan.logic.validators.natural_number_validator(value, context)
ckan.logic.validators.is_positive_integer(value, context)
ckan.logic.validators.boolean_validator(value, context)

Return a boolean for value. Return value when value is a python bool type. Return True for strings ‘true’, ‘yes’, ‘t’, ‘y’, and ‘1’. Return False in all other cases, including when value is an empty string or None

ckan.logic.validators.isodate(value, context)
ckan.logic.validators.no_http(value, context)
ckan.logic.validators.package_id_exists(value, context)
ckan.logic.validators.package_id_does_not_exist(value, context)
ckan.logic.validators.package_name_exists(value, context)
ckan.logic.validators.package_id_or_name_exists(package_id_or_name, context)

Return the given package_id_or_name if such a package exists.

Raises:ckan.lib.navl.dictization_functions.Invalid if there is no package with the given id or name
ckan.logic.validators.resource_id_exists(value, context)
ckan.logic.validators.user_id_exists(user_id, context)

Raises Invalid if the given user_id does not exist in the model given in the context, otherwise returns the given user_id.

ckan.logic.validators.user_id_or_name_exists(user_id_or_name, context)

Return the given user_id_or_name if such a user exists.

Raises:ckan.lib.navl.dictization_functions.Invalid if no user can be found with the given id or user name
ckan.logic.validators.group_id_exists(group_id, context)

Raises Invalid if the given group_id does not exist in the model given in the context, otherwise returns the given group_id.

ckan.logic.validators.group_id_or_name_exists(reference, context)

Raises Invalid if a group identified by the name or id cannot be found.

ckan.logic.validators.activity_type_exists(activity_type)

Raises Invalid if there is no registered activity renderer for the given activity_type. Otherwise returns the given activity_type.

This just uses object_id_validators as a lookup. very safe.

ckan.logic.validators.object_id_validator(key, activity_dict, errors, context)

Validate the ‘object_id’ value of an activity_dict.

Uses the object_id_validators dict (above) to find and call an ‘object_id’ validator function for the given activity_dict’s ‘activity_type’ value.

Raises Invalid if the model given in context contains no object of the correct type (according to the ‘activity_type’ value of the activity_dict) with the given ID.

Raises Invalid if there is no object_id_validator for the activity_dict’s ‘activity_type’ value.

ckan.logic.validators.name_validator(value, context)

Return the given value if it’s a valid name, otherwise raise Invalid.

If it’s a valid name, the given value will be returned unmodified.

This function applies general validation rules for names of packages, groups, users, etc.

Most schemas also have their own custom name validator function to apply custom validation rules after this function, for example a package_name_validator() to check that no package with the given name already exists.

Raises ckan.lib.navl.dictization_functions.Invalid:
 if value is not a valid name
ckan.logic.validators.package_name_validator(key, data, errors, context)
ckan.logic.validators.package_version_validator(value, context)
ckan.logic.validators.duplicate_extras_key(key, data, errors, context)
ckan.logic.validators.group_name_validator(key, data, errors, context)
ckan.logic.validators.tag_length_validator(value, context)
ckan.logic.validators.tag_name_validator(value, context)
ckan.logic.validators.tag_not_uppercase(value, context)
ckan.logic.validators.tag_string_convert(key, data, errors, context)

Takes a list of tags that is a comma-separated string (in data[key]) and parses tag names. These are added to the data dict, enumerated. They are also validated.

ckan.logic.validators.ignore_not_admin(key, data, errors, context)
ckan.logic.validators.ignore_not_package_admin(key, data, errors, context)

Ignore if the user is not allowed to administer the package specified.

ckan.logic.validators.ignore_not_sysadmin(key, data, errors, context)

Ignore the field if user not sysadmin or ignore_auth in context.

ckan.logic.validators.ignore_not_group_admin(key, data, errors, context)

Ignore if the user is not allowed to administer for the group specified.

ckan.logic.validators.user_name_validator(key, data, errors, context)

Validate a new user name.

Append an error message to errors[key] if a user named data[key] already exists. Otherwise, do nothing.

Raises ckan.lib.navl.dictization_functions.Invalid:
 if data[key] is not a string
Return type:None
ckan.logic.validators.user_both_passwords_entered(key, data, errors, context)
ckan.logic.validators.user_password_validator(key, data, errors, context)
ckan.logic.validators.user_passwords_match(key, data, errors, context)
ckan.logic.validators.user_password_not_empty(key, data, errors, context)

Only check if password is present if the user is created via action API. If not, user_both_passwords_entered will handle the validation

ckan.logic.validators.user_about_validator(value, context)
ckan.logic.validators.vocabulary_name_validator(name, context)
ckan.logic.validators.vocabulary_id_not_changed(value, context)
ckan.logic.validators.vocabulary_id_exists(value, context)
ckan.logic.validators.tag_in_vocabulary_validator(value, context)
ckan.logic.validators.tag_not_in_vocabulary(key, tag_dict, errors, context)
ckan.logic.validators.url_validator(key, data, errors, context)

Checks that the provided value (if it is present) is a valid URL

ckan.logic.validators.user_name_exists(user_name, context)
ckan.logic.validators.role_exists(role, context)
ckan.logic.validators.datasets_with_no_organization_cannot_be_private(key, data, errors, context)
ckan.logic.validators.list_of_strings(key, data, errors, context)
ckan.logic.validators.if_empty_guess_format(key, data, errors, context)
ckan.logic.validators.clean_format(format)
ckan.logic.validators.no_loops_in_hierarchy(key, data, errors, context)

Checks that the parent groups specified in the data would not cause a loop in the group hierarchy, and therefore cause the recursion up/down the hierarchy to get into an infinite loop.

ckan.logic.validators.filter_fields_and_values_should_have_same_length(key, data, errors, context)
ckan.logic.validators.filter_fields_and_values_exist_and_are_valid(key, data, errors, context)
ckan.logic.validators.extra_key_not_in_root_schema(key, data, errors, context)
ckan.logic.validators.empty_if_not_sysadmin(key, data, errors, context)

Only sysadmins may pass this value

ckan.logic.converters.convert_to_extras(key, data, errors, context)
ckan.logic.converters.convert_from_extras(key, data, errors, context)
ckan.logic.converters.extras_unicode_convert(extras, context)
ckan.logic.converters.free_tags_only(key, data, errors, context)
ckan.logic.converters.convert_to_tags(vocab)
ckan.logic.converters.convert_from_tags(vocab)
ckan.logic.converters.convert_user_name_or_id_to_id(user_name_or_id, context)

Return the user id for the given user name or id.

The point of this function is to convert user names to ids. If you have something that may be a user name or a user id you can pass it into this function and get the user id out either way.

Also validates that a user with the given name or id exists.

Returns:the id of the user with the given user name or id
Return type:string
Raises:ckan.lib.navl.dictization_functions.Invalid if no user can be found with the given id or user name
ckan.logic.converters.convert_package_name_or_id_to_id(package_name_or_id, context)

Return the package id for the given package name or id.

The point of this function is to convert package names to ids. If you have something that may be a package name or id you can pass it into this function and get the id out either way.

Also validates that a package with the given name or id exists.

Returns:the id of the package with the given name or id
Return type:string
Raises:ckan.lib.navl.dictization_functions.Invalid if there is no package with the given name or id
ckan.logic.converters.convert_group_name_or_id_to_id(group_name_or_id, context)

Return the group id for the given group name or id.

The point of this function is to convert group names to ids. If you have something that may be a group name or id you can pass it into this function and get the id out either way.

Also validates that a group with the given name or id exists.

Returns:the id of the group with the given name or id
Return type:string
Raises:ckan.lib.navl.dictization_functions.Invalid if there is no group with the given name or id
ckan.logic.converters.convert_to_json_if_string(value, context)
ckan.logic.converters.convert_to_list_if_string(value, context=None)
ckan.logic.converters.remove_whitespace(value, context)