# SPDX-FileCopyrightText: 2026 Helmholtz-Zentrum Dresden-Rossendorf e.V (HZDR)
# SPDX-License-Identifier: Apache-2.0
"""Shared UI feedback helpers for form-based routes."""
from __future__ import annotations
import logging
from flask import flash, session
from flask_login import current_user
DEMO_LIMIT_MESSAGE = (
"Demo limit reached. Install a full LabFrog instance to save more entries."
)
[docs]
def flash_demo_limit_reached() -> None:
"""Show the shared demo-limit warning and discard stale form flashes."""
session.pop("_flashes", None)
flash(DEMO_LIMIT_MESSAGE, "warning")
[docs]
def current_username(*, default: str = "anonymous") -> str:
"""Return the active username for persistence/audit fields."""
if current_user and current_user.is_authenticated:
return str(current_user.username)
return default