Skip to content

Helper Functions

charts_allow_anon_building_charts()

Check if anonymous users are allowed to build charts.

RETURNS DESCRIPTION
bool

True if anonymous users are allowed to build charts, False otherwise.

TYPE: bool

Source code in ckanext/charts/helpers.py
83
84
85
86
87
88
89
def charts_allow_anon_building_charts() -> bool:
    """Check if anonymous users are allowed to build charts.

    Returns:
        bool: True if anonymous users are allowed to build charts, False otherwise.
    """
    return config.allow_anon_building_charts()

charts_get_resource_columns(resource_id)

Get the columns of the given resource.

PARAMETER DESCRIPTION
resource_id

Resource ID

TYPE: str

RETURNS DESCRIPTION
str

JSON string of columns options

TYPE: str

Source code in ckanext/charts/helpers.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def charts_get_resource_columns(resource_id: str) -> str:
    """Get the columns of the given resource.

    Args:
        resource_id: Resource ID

    Returns:
        str: JSON string of columns options
    """
    fetcher = DatastoreDataFetcher(resource_id)

    return json.dumps(
        [{"id": col, "title": col} for col in fetcher.fetch_data().columns],
    )

charts_include_htmx_asset()

Checks if the HTMX asset should be included.

RETURNS DESCRIPTION
bool

True if the HTMX asset should be included, False otherwise.

TYPE: bool

Source code in ckanext/charts/helpers.py
40
41
42
43
44
45
46
def charts_include_htmx_asset() -> bool:
    """Checks if the HTMX asset should be included.

    Returns:
        bool: True if the HTMX asset should be included, False otherwise.
    """
    return config.include_htmx_asset()

charts_reinit_ckan_js_modules()

Checks if CKAN JS modules should be reinitialized.

RETURNS DESCRIPTION
bool

True if CKAN JS modules should be reinitialized, False otherwise.

TYPE: bool

Source code in ckanext/charts/helpers.py
49
50
51
52
53
54
55
def charts_reinit_ckan_js_modules() -> bool:
    """Checks if CKAN JS modules should be reinitialized.

    Returns:
        bool: True if CKAN JS modules should be reinitialized, False otherwise.
    """
    return config.reinit_ckan_js_modules()

charts_user_is_authenticated()

Check if the user is authenticated.

RETURNS DESCRIPTION
bool

True if the user is authenticated, False otherwise.

TYPE: bool

Source code in ckanext/charts/helpers.py
74
75
76
77
78
79
80
def charts_user_is_authenticated() -> bool:
    """Check if the user is authenticated.

    Returns:
        bool: True if the user is authenticated, False otherwise.
    """
    return tk.current_user.is_authenticated

get_available_chart_engines_options()

Get the available chart engines.

RETURNS DESCRIPTION
list[dict[str, str]]

List of chart engines options

Source code in ckanext/charts/helpers.py
31
32
33
34
35
36
37
def get_available_chart_engines_options() -> list[dict[str, str]]:
    """Get the available chart engines.

    Returns:
        List of chart engines options
    """
    return [{"value": engine, "text": engine} for engine in get_chart_engines()]

get_file_cache_size()

Get the size of the file cache in a human-readable format.

RETURNS DESCRIPTION
str

Human-readable file cache size

TYPE: str

Source code in ckanext/charts/helpers.py
22
23
24
25
26
27
28
def get_file_cache_size() -> str:
    """Get the size of the file cache in a human-readable format.

    Returns:
        str: Human-readable file cache size
    """
    return utils.printable_file_size(count_file_cache_size())

get_redis_cache_size()

Get the size of the Redis cache in a human-readable format.

RETURNS DESCRIPTION
str

Human-readable Redis cache size

TYPE: str

Source code in ckanext/charts/helpers.py
13
14
15
16
17
18
19
def get_redis_cache_size() -> str:
    """Get the size of the Redis cache in a human-readable format.

    Returns:
        str: Human-readable Redis cache size
    """
    return utils.printable_file_size(count_redis_cache_size())