From a1000824e6dfdc8843547b4848e58a9c1eed82d8 Mon Sep 17 00:00:00 2001 From: mutantsan Date: Fri, 12 Jul 2024 07:15:29 +0300 Subject: [PATCH] fix: clear validators cache in declare_config_options to use custom validator --- ckanext/charts/plugin.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ckanext/charts/plugin.py b/ckanext/charts/plugin.py index 4896291..7580c12 100644 --- a/ckanext/charts/plugin.py +++ b/ckanext/charts/plugin.py @@ -1,11 +1,16 @@ from __future__ import annotations from typing import Any +from os import path + +from yaml import safe_load import ckan.plugins as p import ckan.plugins.toolkit as tk +import ckan.logic as logic from ckan import types from ckan.common import CKANConfig +from ckan.config.declaration import Declaration, Key import ckanext.charts.config as conf import ckanext.charts.utils as utils @@ -17,10 +22,10 @@ @tk.blanket.helpers @tk.blanket.blueprints -@tk.blanket.config_declarations @tk.blanket.validators class ChartsViewPlugin(p.SingletonPlugin): p.implements(p.IConfigurer) + p.implements(p.IConfigDeclaration) p.implements(p.IResourceView) p.implements(p.IBlueprint) p.implements(p.ISignal) @@ -43,6 +48,17 @@ def update_config(self, config_: CKANConfig): tk.add_public_directory(config_, "public") tk.add_resource("assets", "charts") + # IConfigDeclaration + + def declare_config_options(self, declaration: Declaration, key: Key): + """Allow usage of custom validators by clearing the validators cache""" + logic.clear_validators_cache() + + with open(path.dirname(__file__) + "/config_declaration.yaml") as file: + data_dict = safe_load(file) + + return declaration.load_dict(data_dict) + # IResourceView def info(self) -> dict[str, Any]: