Skip to content

Commit

Permalink
add file for constants - move alert constants to file - remove link f…
Browse files Browse the repository at this point in the history
…rom warning on save (#339)
  • Loading branch information
tilen1976 authored May 7, 2024
1 parent 8875b15 commit ce4c46c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 33 deletions.
21 changes: 1 addition & 20 deletions src/datadoc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions src/datadoc/constants.py
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 3 additions & 4 deletions src/datadoc/frontend/callbacks/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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,
)
2 changes: 0 additions & 2 deletions src/datadoc/frontend/callbacks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
10 changes: 3 additions & 7 deletions src/datadoc/frontend/callbacks/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
)

0 comments on commit ce4c46c

Please sign in to comment.