Skip to content

Helper Functions

CKAN helper functions are typically used in templates, but also available everywhere with toolkit.h.helper_name().

tables_get_filters_from_request()

Get the filters from the request arguments.

RETURNS DESCRIPTION
list[FilterItem]

A dictionary of filters

Source code in ckanext/tables/helpers.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def tables_get_filters_from_request() -> list[table.FilterItem]:
    """Get the filters from the request arguments.

    Returns:
        A dictionary of filters
    """
    fields = tk.request.args.getlist("field")
    operators = tk.request.args.getlist("operator")
    values = tk.request.args.getlist("value")

    return [
        table.FilterItem(field=field, operator=op, value=value)
        for field, op, value in zip(fields, operators, values, strict=True)
    ]

tables_json_dumps(value)

Convert a value to a JSON string.

PARAMETER DESCRIPTION
value

The value to convert to a JSON string

TYPE: Any

RETURNS DESCRIPTION
str

The JSON string

Source code in ckanext/tables/helpers.py
10
11
12
13
14
15
16
17
18
19
def tables_json_dumps(value: Any) -> str:
    """Convert a value to a JSON string.

    Args:
        value: The value to convert to a JSON string

    Returns:
        The JSON string
    """
    return json.dumps(value)