Rend les plages horaires et les rappels ntfy configurables, supprime le

classement, ajoute une suite de tests pytest

- calcul.py: matin_debut/fin, aprem_debut/fin et pause_dejeuner_fin sont
  paramétrables via config.json > plages (moteur de calcul de l'heure de
  sortie optimale inclus, pas seulement l'affichage). Défauts identiques
  à l'ancien comportement, validé par la suite de tests.
- stats.py: les seuils de conformité utilisent la même config.
- main.py/templates: warn de saisie et suffixes de cible dynamiques.
- Rappels ntfy: serveur, topic et plage horaire (rappel_debut_h/fin_h)
  configurables par utilisateur depuis /settings, plus en dur dans le code.
- Page classement supprimée (pas de compétition entre utilisateurs).
- Nouvelle suite pytest (app/tests/), à lancer via
  `docker compose run --rm pointeuse pytest -v`.
This commit is contained in:
Antoine
2026-07-17 22:40:55 +02:00
parent 0b47e4a625
commit c2d7d0e3ac
19 changed files with 419 additions and 415 deletions

View File

@ -3,6 +3,8 @@ import json
import secrets
from pathlib import Path
from calcul import DEFAULT_PLAGES
DATA_DIR = Path("/data")
CONFIG_FILE = DATA_DIR / "config.json"
@ -18,6 +20,7 @@ DEFAULT_CONFIG = {
"password": "",
"use_tls": True,
},
"plages": dict(DEFAULT_PLAGES),
}
# ── User path helpers ──────────────────────────────────────────────────────────
@ -142,24 +145,41 @@ def _notif_file(user_id: str) -> Path:
return _user_root(user_id) / "notif.json"
DEFAULT_NTFY_SERVER = "https://ntfy.sh"
DEFAULT_RAPPEL_DEBUT_H = 7
DEFAULT_RAPPEL_FIN_H = 20
def load_notif_config(user_id: str) -> dict:
"""Return {"ntfy_topic": str|None, "token": str}, generating a token on first use."""
"""Return {"ntfy_topic", "ntfy_server", "rappel_debut_h", "rappel_fin_h", "token"}."""
f = _notif_file(user_id)
if f.exists():
cfg = json.loads(f.read_text())
cfg.setdefault("ntfy_server", DEFAULT_NTFY_SERVER)
cfg.setdefault("rappel_debut_h", DEFAULT_RAPPEL_DEBUT_H)
cfg.setdefault("rappel_fin_h", DEFAULT_RAPPEL_FIN_H)
if cfg.get("token"):
return cfg
else:
cfg = {"ntfy_topic": None}
cfg = {
"ntfy_topic": None, "ntfy_server": DEFAULT_NTFY_SERVER,
"rappel_debut_h": DEFAULT_RAPPEL_DEBUT_H, "rappel_fin_h": DEFAULT_RAPPEL_FIN_H,
}
cfg["token"] = secrets.token_hex(16)
_ensure_user_dirs(user_id)
f.write_text(json.dumps(cfg, indent=2, ensure_ascii=False))
return cfg
def save_notif_config(user_id: str, ntfy_topic: str):
def save_notif_config(
user_id: str, ntfy_topic: str, ntfy_server: str = "",
rappel_debut_h: int = DEFAULT_RAPPEL_DEBUT_H, rappel_fin_h: int = DEFAULT_RAPPEL_FIN_H,
):
cfg = load_notif_config(user_id)
cfg["ntfy_topic"] = ntfy_topic.strip() or None
cfg["ntfy_server"] = ntfy_server.strip().rstrip("/") or DEFAULT_NTFY_SERVER
cfg["rappel_debut_h"] = rappel_debut_h
cfg["rappel_fin_h"] = rappel_fin_h
_ensure_user_dirs(user_id)
_notif_file(user_id).write_text(json.dumps(cfg, indent=2, ensure_ascii=False))