Skip to content

Utils

get_datastore_field_types()

Get a dict of datastore field names and their types.

Returns:

Type Description

a dict of {field_name: field_type}

Source code in ckanext/graph/lib/utils.py
11
12
13
14
15
16
17
18
19
20
21
22
def get_datastore_field_types():
    """
    Get a dict of datastore field names and their types.

    :returns: a dict of {field_name: field_type}
    """
    data = {
        'resource_id': toolkit.c.resource['id'],
        'limit': 0,
    }
    results = toolkit.get_action('datastore_search')({}, data)
    return {field['id']: field['type'] for field in results.get('fields', [])}

get_request_filters()

Retrieve filters from the URL parameters and return them as a dict.

Returns:

Type Description

a dict of {field_name: [filter1,filter2,...]}

Source code in ckanext/graph/lib/utils.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def get_request_filters():
    """
    Retrieve filters from the URL parameters and return them as a dict.

    :returns: a dict of {field_name: [filter1,filter2,...]}
    """
    filters = {}
    for f in unquote(toolkit.request.params.get('filters', '')).split('|'):
        if f:
            k, v = f.split(':', 1)
            if k not in filters:
                filters[k] = []
            filters[k].append(v)
    return filters

get_request_query()

Retrieve the q parameter from the URL and return unquoted.

Returns:

Type Description

string

Source code in ckanext/graph/lib/utils.py
41
42
43
44
45
46
47
48
def get_request_query():
    """
    Retrieve the q parameter from the URL and return unquoted.

    :returns: string
    """
    q = unquote(toolkit.request.params.get('q', ''))
    return q if q and q != '' else None