CKAN 2.2.3 documentation » Writing CKAN extensions »

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)
ckan.logic.validators.natural_number_validator(value, context)
ckan.logic.validators.is_positive_integer(value, context)
ckan.logic.validators.boolean_validator(value, context)
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_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.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.related_id_exists(related_id, context)

Raises Invalid if the given related_id does not exist in the model given in the context, otherwise returns the given related_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.resource_id_exists(value, context)
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.extras_unicode_convert(extras, context)
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.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.