Skip to content

Validators

is_datastore_field(value, context) ΒΆ

Make sure this field is an actual datastore field.

Parameters:

Name Type Description Default
value

list of field names

required
context

the validation context

required

Returns:

Type Description

the value if it's valid

Source code in ckanext/gallery/logic/validators.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def is_datastore_field(value, context):
    """
    Make sure this field is an actual datastore field.

    :param value: list of field names
    :param context: the validation context
    :raises: toolkit.Invalid if the field is not in the resource's datastore
    :returns: the value if it's valid
    """
    fields = get_datastore_fields(toolkit.c.resource.get('id'))
    for field in fields:
        if field['id'] in value:
            return value
    raise toolkit.Invalid(toolkit._('Field {0} not in datastore'.format(value)))