Skip to content

Schema

list_of_strings(delimiter=',') ΒΆ

Creates a converter/validator function which when given a value return a list or raises an error if a list can't be created from the value. If the value passed in is a list already it is returned with no modifications, if it's a string then the delimiter is used to split the string and the result is returned. If the value is neither a list or a string then an error is raised.

Parameters:

Name Type Description Default
delimiter

the string to delimit the value on, if it's a string. Defaults to a comma

','

Returns:

Type Description

a list

Source code in ckanext/query_dois/logic/schema.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def list_of_strings(delimiter=','):
    """
    Creates a converter/validator function which when given a value return a list or
    raises an error if a list can't be created from the value. If the value passed in is
    a list already it is returned with no modifications, if it's a string then the
    delimiter is used to split the string and the result is returned. If the value is
    neither a list or a string then an error is raised.

    :param delimiter: the string to delimit the value on, if it's a string. Defaults to
        a comma
    :returns: a list
    """

    def validator(value):
        if isinstance(value, list):
            return value
        if isinstance(value, str):
            return value.split(delimiter)
        raise toolkit.Invalid('Invalid list of strings')

    return validator