Skip to content

Config

get_debug(default=True)

Get the debug value from the config. Checks both debug and DEBUG and returns the default if neither is set.

Parameters:

Name Type Description Default
default

returns this if neither is set

True

Returns:

Type Description

True if debug mode is enabled

Source code in ckantools/config.py
26
27
28
29
30
31
32
33
34
def get_debug(default=True):
    """
    Get the debug value from the config. Checks both `debug` and `DEBUG` and returns the
    default if neither is set.

    :param default: returns this if neither is set
    :return: True if debug mode is enabled
    """
    return toolkit.asbool(get_setting('debug', 'DEBUG', default=default))

get_setting(*config_names, default=None)

Get a configuration value, with multiple backup options if the first isn't set. e.g. get_setting('ckanext.my_ext.site_name', 'ckan.site_title', default='Unknown') will check ckanext.my_ext.site_name first, then ckanext.site_title if that's not set, and finally use the default if neither is set.

Parameters:

Name Type Description Default
config_names

the names of the config settings to check, in descending order of priority

()
default

the value to use if none of the config values are set

None

Returns:

Type Description

the value of one of the config settings, or the default if none are set

Source code in ckantools/config.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def get_setting(*config_names, default=None):
    """
    Get a configuration value, with multiple backup options if the first isn't set. e.g.
    `get_setting('ckanext.my_ext.site_name', 'ckan.site_title', default='Unknown')` will
    check `ckanext.my_ext.site_name` first, then `ckanext.site_title` if that's not set,
    and finally use the default if neither is set.

    :param config_names: the names of the config settings to check, in descending order
        of priority
    :param default: the value to use if none of the config values are set
    :return: the value of one of the config settings, or the default if none are set
    """
    for c in config_names:
        setting = toolkit.config.get(c)
        if setting is not None:
            return setting
    return default