From ce4c46ca296a877f36341bca087cc30256970237 Mon Sep 17 00:00:00 2001 From: Cecilie Seim <68303562+tilen1976@users.noreply.github.com> Date: Tue, 7 May 2024 10:06:20 +0200 Subject: [PATCH] add file for constants - move alert constants to file - remove link from warning on save (#339) --- src/datadoc/config.py | 21 +-------------------- src/datadoc/constants.py | 6 ++++++ src/datadoc/frontend/callbacks/dataset.py | 7 +++---- src/datadoc/frontend/callbacks/utils.py | 2 -- src/datadoc/frontend/callbacks/variables.py | 10 +++------- 5 files changed, 13 insertions(+), 33 deletions(-) create mode 100644 src/datadoc/constants.py diff --git a/src/datadoc/config.py b/src/datadoc/config.py index b43153d1..c67bdd38 100644 --- a/src/datadoc/config.py +++ b/src/datadoc/config.py @@ -11,6 +11,7 @@ from dotenv import dotenv_values from dotenv import load_dotenv +from datadoc.constants import DAPLA_MANUAL_TEXT from datadoc.enums import DaplaRegion from datadoc.enums import DaplaService from datadoc.frontend.components.builders import build_link_object @@ -25,10 +26,6 @@ DAPLA_REGION = "DAPLA_REGION" DAPLA_SERVICE = "DAPLA_SERVICE" -DAPLA_MANUAL_TEXT = "Dapla manual navnestandard" -DATASET_INFO_TEXT = "Datadoc - obligatorisk og anbefalte metadata" -VARIABLE_INFO_TEXT = "Variabelforekomst" - env_loaded = False @@ -167,19 +164,3 @@ def get_dapla_manual_naming_standard_url() -> dict | None: if link_href is None: return None return build_link_object(DAPLA_MANUAL_TEXT, link_href) - - -def get_dataset_metadata_info() -> dict | None: - """Get the URL to metadata dataset info.""" - link_href = _get_config_item("METADATA_DATASET_INFO") - if link_href is None: - return None - return build_link_object(DATASET_INFO_TEXT, link_href) - - -def get_variable_metadata_info() -> dict | None: - """Get the URL to metadata variable info.""" - link_href = _get_config_item("METADATA_VARIABLE_INFO") - if link_href is None: - return None - return build_link_object(VARIABLE_INFO_TEXT, link_href) diff --git a/src/datadoc/constants.py b/src/datadoc/constants.py new file mode 100644 index 00000000..f86a6455 --- /dev/null +++ b/src/datadoc/constants.py @@ -0,0 +1,6 @@ +"""Repository for constant values in Datadoc.""" + +MISSING_METADATA_WARNING = "Advarsel - obligatorisk metadata mangler" +CHECK_OBLIGATORY_METADATA_DATASET_MESSAGE = "Følgende datasett felt har ikke verdi:" +CHECK_OBLIGATORY_METADATA_VARIABLES_MESSAGE = "Følgende variabler har felt uten verdi:" +DAPLA_MANUAL_TEXT = "Dapla manual navnestandard" diff --git a/src/datadoc/frontend/callbacks/dataset.py b/src/datadoc/frontend/callbacks/dataset.py index c34814c2..be3f680a 100644 --- a/src/datadoc/frontend/callbacks/dataset.py +++ b/src/datadoc/frontend/callbacks/dataset.py @@ -12,7 +12,8 @@ from datadoc import state from datadoc.backend.dapla_dataset_path_info import DaplaDatasetPathInfo from datadoc.backend.datadoc_metadata import DataDocMetadata -from datadoc.frontend.callbacks.utils import MISSING_METADATA_WARNING +from datadoc.constants import CHECK_OBLIGATORY_METADATA_DATASET_MESSAGE +from datadoc.constants import MISSING_METADATA_WARNING from datadoc.frontend.callbacks.utils import MetadataInputTypes from datadoc.frontend.callbacks.utils import find_existing_language_string from datadoc.frontend.callbacks.utils import get_dataset_path @@ -54,8 +55,6 @@ logger = logging.getLogger(__name__) -CHECK_OBLIGATORY_METADATA_DATASET_MESSAGE = "Følgende datasett felt mangler metadata som kan være obligatorisk for ditt datasett:" - def open_file(file_path: str | None = None) -> DataDocMetadata: """Load the given dataset into a DataDocMetadata instance.""" @@ -306,6 +305,6 @@ def dataset_metadata_control() -> dbc.Alert | None: AlertTypes.WARNING, MISSING_METADATA_WARNING, CHECK_OBLIGATORY_METADATA_DATASET_MESSAGE, - config.get_dataset_metadata_info(), + None, missing_metadata, ) diff --git a/src/datadoc/frontend/callbacks/utils.py b/src/datadoc/frontend/callbacks/utils.py index eccf0c98..890ed004 100644 --- a/src/datadoc/frontend/callbacks/utils.py +++ b/src/datadoc/frontend/callbacks/utils.py @@ -33,8 +33,6 @@ str | list[str] | int | float | bool | datetime.date | None ) -MISSING_METADATA_WARNING = "Advarsel - obligatorisk metadata ikke utfylt" - def get_language_strings_enum( enum: Enum | type[enums.LanguageStringsEnum], diff --git a/src/datadoc/frontend/callbacks/variables.py b/src/datadoc/frontend/callbacks/variables.py index db07ae63..2c68f0c9 100644 --- a/src/datadoc/frontend/callbacks/variables.py +++ b/src/datadoc/frontend/callbacks/variables.py @@ -7,9 +7,9 @@ from pydantic import ValidationError -from datadoc import config from datadoc import state -from datadoc.frontend.callbacks.utils import MISSING_METADATA_WARNING +from datadoc.constants import CHECK_OBLIGATORY_METADATA_VARIABLES_MESSAGE +from datadoc.constants import MISSING_METADATA_WARNING from datadoc.frontend.callbacks.utils import MetadataInputTypes from datadoc.frontend.callbacks.utils import find_existing_language_string from datadoc.frontend.callbacks.utils import get_metadata_field_display_name @@ -43,10 +43,6 @@ logger = logging.getLogger(__name__) -CHECK_OBLIGATORY_METADATA_VARIABLES_MESSAGE = ( - "Følgende variabler mangler metadata som kan være obligatorisk for ditt datasett:" -) - def populate_variables_workspace( variables: list[model.Variable], @@ -357,6 +353,6 @@ def variables_metadata_control() -> dbc.Alert | None: AlertTypes.WARNING, MISSING_METADATA_WARNING, CHECK_OBLIGATORY_METADATA_VARIABLES_MESSAGE, - config.get_variable_metadata_info(), + None, missing_metadata, )