from __future__ import annotations from dataclasses import dataclass from app.modules.orion.html import text @dataclass(frozen=True) class ResultPresentation: key: str label: str css_class: str color: str RESULT_PRESENTATIONS: dict[str, ResultPresentation] = { "BESTANDEN": ResultPresentation("BESTANDEN", "Bestanden", "result-box--passed", "#245C36"), "BESTANDEN_MIT_AUFLAGEN": ResultPresentation( "BESTANDEN_MIT_AUFLAGEN", "Bestanden mit Auflagen", "result-box--conditional", "#7A5A00", ), "NICHT_BESTANDEN": ResultPresentation( "NICHT_BESTANDEN", "Nicht bestanden", "result-box--failed", "#7A1F26", ), "OFFEN": ResultPresentation("OFFEN", "Noch nicht bewertet", "result-box--open", "#2E3B40"), } RESULT_ALIASES = { "": "OFFEN", "OFFEN": "OFFEN", "BESTANDEN": "BESTANDEN", "BESTANDEN_MIT_AUFLAGEN": "BESTANDEN_MIT_AUFLAGEN", "NICHT_BESTANDEN": "NICHT_BESTANDEN", "offen": "OFFEN", "bestanden": "BESTANDEN", "bestanden_mit_auflagen": "BESTANDEN_MIT_AUFLAGEN", "mit_auflagen": "BESTANDEN_MIT_AUFLAGEN", "bestanden mit Auflagen": "BESTANDEN_MIT_AUFLAGEN", "nicht_bestanden": "NICHT_BESTANDEN", "nicht bestanden": "NICHT_BESTANDEN", } def validation_result_presentation(value: str | None) -> ResultPresentation: key = RESULT_ALIASES.get(str(value or "").strip(), "OFFEN") return RESULT_PRESENTATIONS[key] def validation_result_label(value: str | None) -> str: return validation_result_presentation(value).label def validation_result_cover_sentence(value: str | None) -> str: presentation = validation_result_presentation(value) sentences = { "BESTANDEN": "Die technische Validierung wurde erfolgreich bestanden.", "BESTANDEN_MIT_AUFLAGEN": "Die technische Validierung wurde mit Auflagen bestanden.", "NICHT_BESTANDEN": "Die technische Validierung wurde nicht bestanden.", "OFFEN": "Die technische Validierung wurde noch nicht bewertet.", } return sentences[presentation.key] def validation_result_box(value: str | None, *, compact: bool = False) -> str: presentation = validation_result_presentation(value) size_class = "result-box--compact" if compact else "result-box--cover" return ( f'
' '
VALIDIERUNGSERGEBNIS
' f'
{text(presentation.label.upper() if not compact else presentation.label)}
' "
" )