from ..retention import COUNT_KEYS, SETTINGS, validate_values from .sections import Field, Section SLUG = "retention" RUN_PATH = "/retention/run" COUNT_LABELS = { "alerts": "Alarme", "deliveries": "Zustellungen", "agent_runs": "Agenten-Läufe", "state_log": "Statusverlauf", "audit": "Audit-Einträge", "mutes": "Stummschaltungen", } def format_counts(counts: dict[str, int]) -> str: return ", ".join(f"{COUNT_LABELS[key]}: {counts.get(key, 0)}" for key in COUNT_KEYS) def context(state) -> dict: last = state.runtime.retention.last_run() return { "retention_last": last, "retention_counts": format_counts(last.counts) if last else "", "retention_settings": SETTINGS, "retention_run_path": RUN_PATH, } SECTION = Section( slug=SLUG, title="Aufbewahrung", fields=tuple( Field(s.key, f"{s.label} in Tagen ({s.minimum} bis {s.maximum})", default=str(s.default), placeholder=f"{s.minimum} bis {s.maximum}") for s in SETTINGS ), validate=validate_values, optional=True, extra_template="_retention_extra.html", extra_context=context, )