Skip to content

Helper Functions

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

tables_get_table(table_name)

Get a table definition by its name.

PARAMETER DESCRIPTION
table_name

The name of the table to get

TYPE: str

RETURNS DESCRIPTION
TableDefinition | None

The table definition or None if the table does not exist

Source code in ckanext/tables/helpers.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def tables_get_table(table_name: str) -> table.TableDefinition | None:
    """Get a table definition by its name.

    Args:
        table_name: The name of the table to get

    Returns:
        The table definition or None if the table does not exist
    """
    table_class = table.table_registry.get(table_name)

    if not table_class:
        return None

    try:
        table_class.check_access({"user": tk.current_user.name})
    except tk.NotAuthorized:
        return None

    return table_class

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
 9
10
11
12
13
14
15
16
17
18
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)