66 lines
2 KiB
Python
66 lines
2 KiB
Python
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_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'<div class="result-box {size_class} {presentation.css_class}">'
|
|
'<div class="result-box__label">VALIDIERUNGSERGEBNIS</div>'
|
|
f'<div class="result-box__value">{text(presentation.label.upper() if not compact else presentation.label)}</div>'
|
|
"</div>"
|
|
)
|