Skip to content

Lib

get_datastore_fields(resource_id, context) ΒΆ

Returns a list of alphabetically sorted field names for the given resource id from the datastore.

Parameters:

Name Type Description Default
resource_id

the resource's ID

required
context

the context to use when calling the datastore_search action

required

Returns:

Type Description

list of field names

Source code in ckanext/list/lib.py
10
11
12
13
14
15
16
17
18
19
20
21
def get_datastore_fields(resource_id, context):
    """
    Returns a list of alphabetically sorted field names for the given resource id from
    the datastore.

    :param resource_id: the resource's ID
    :param context: the context to use when calling the datastore_search action
    :return: list of field names
    """
    data = {'resource_id': resource_id, 'limit': 0}
    fields = toolkit.get_action('datastore_search')(context, data).get('fields', {})
    return sorted([f['id'] for f in fields])