Utility Functions
Utility functions are meant to be used in the extension codebase to perform some specific tasks. They are defined in the utils.py
file of the extension.
Some utils functions could be useful for other extensions as well. You can use them by importing the ap_main.utils
module.
import ckanext.admin_panel.utils as ap_utils
List of Utility Functions
ap_before_request()
Check if user has access to the admin panel.
Calls admin_panel_access
auth function to check if user has access to the
admin panel view. If you want to change the auth function logic, you can chain it.
RAISES | DESCRIPTION |
---|---|
NotAuthorized
|
If user does not have access to the admin panel |
Example
from flask import Blueprint, Response
from ckanext.ap_main.utils import ap_before_request
blueprint = Blueprint("my_blueprint", __name__, url_prefix="/admin-panel/my_blueprint")
blueprint.before_request(ap_before_request)
Source code in ckanext/ap_main/utils.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
get_all_renderers()
Get all registered column renderers.
A renderer is a function that takes a column value and can modify its appearance in a table.
RETURNS | DESCRIPTION |
---|---|
dict[str, ColRenderer]
|
A mapping of renderer names to renderer functions |
Source code in ckanext/ap_main/utils.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
get_config_schema(schema_id)
Get a schema by its id from the loaded schemas.
PARAMETER | DESCRIPTION |
---|---|
schema_id
|
The id of the schema to get
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[Any, Any] | None
|
The schema if found, otherwise None |
Source code in ckanext/ap_main/utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|