From 3f1e1621a3743e39724bd806b8e799cffa194c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gastinel?= <264859180+gastinelt@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:37:23 +0100 Subject: [PATCH] Meteo Vercors : afficher le bulletin public sur la carte --- forum/forum.py | 14 ++++++++++ forum/server.py | 14 ++++++++++ forum/tests/test_forum.py | 41 +++++++++++++++++++++++++++++ maquettes/accueil-carte/index.html | 38 +++++++++++++++++++------- maquettes/accueil-carte/modele.html | 38 +++++++++++++++++++------- 5 files changed, 127 insertions(+), 18 deletions(-) diff --git a/forum/forum.py b/forum/forum.py index e9fedae..251d513 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -226,6 +226,20 @@ class Forum: " WHERE p.topic_id=? AND (p.hidden=0 OR ?) ORDER BY p.id", (topic_id, int(voit))).fetchall() return t, msgs + def a_la_une(self): + """Dernier bulletin visible par un visiteur et nombre de nouveaux sujets publics sur sept jours.""" + bulletin = self.con.execute( + "SELECT t.id AS sujet, t.title AS titre, p.body AS corps, u.display_name AS auteur" + " FROM topics t JOIN posts p ON p.topic_id=t.id JOIN users u ON u.id=p.author_id" + " WHERE t.fixed=1 AND t.status='publie' AND t.hidden=0 AND p.hidden=0" + " ORDER BY p.id DESC LIMIT 1" + ).fetchone() + n = self.con.execute( + "SELECT COUNT(*) FROM topics WHERE fixed=0 AND status='publie' AND hidden=0" + " AND created_at >= datetime('now', '-7 days')" + ).fetchone()[0] + return bulletin, n + def en_attente(self, user): self._exiger(user, "valider_sujet") return self.con.execute("SELECT t.*, u.display_name AS auteur FROM topics t JOIN users u ON u.id=t.author_id" diff --git a/forum/server.py b/forum/server.py index ac02a64..cca9108 100644 --- a/forum/server.py +++ b/forum/server.py @@ -685,6 +685,18 @@ class Handler(BaseHTTPRequestHandler): self.envoyer(200, corps, "application/json; charset=utf-8", [("Cache-Control", "public, max-age=300"), ("Access-Control-Allow-Origin", "*")]) + def a_la_une(self): + bulletin, n = self.app.forum.a_la_une() + donnees = {"n": n} + if bulletin: + extrait = " ".join(bulletin["corps"].split()) + if len(extrait) > 180: + extrait = extrait[:179].rstrip() + "…" + donnees.update(titre=bulletin["titre"], auteur=bulletin["auteur"], extrait=extrait, + url=self.prefixe + "/t/%d" % bulletin["sujet"]) + self.envoyer(200, json.dumps(donnees, ensure_ascii=False), "application/json; charset=utf-8", + [("Cache-Control", "no-store")]) + def photo_adhesion(self, user, nom): if not PHOTO_OK.match(nom): return self.envoyer(404, "introuvable", "text/plain; charset=utf-8") @@ -694,6 +706,8 @@ class Handler(BaseHTTPRequestHandler): def do_GET(self): u = urlparse(self.path) u = u._replace(path=self.chemin_sans_prefixe(u.path)) + if u.path == "/api/une.json": + return self.a_la_une() filtre = parse_qs(u.query).get("q", [""])[0].strip()[:80] user = self.utilisateur() f = self.app.forum diff --git a/forum/tests/test_forum.py b/forum/tests/test_forum.py index 7c697e8..c01ca88 100644 --- a/forum/tests/test_forum.py +++ b/forum/tests/test_forum.py @@ -734,6 +734,47 @@ class TestFicheHTTP(BaseHTTP): self.assertEqual(self.f.photos_fiche_ids("geve"), {self.ids[1]}) +class TestUneHTTP(BaseHTTP): + def setUp(self): + super().setUp() + self.reglages.prefixe = "/forum" + self.chemin = "/forum/api/une.json" + self.bulletin = self.f.sujets(None)[0]["id"] + + def test_bulletin_public_et_lien(self): + self.assertEqual(json.loads(self.req(self.chemin)[2]), {"n": 0}) + self.f.repondre(self.pere, self.bulletin, "Ancien bulletin") + self.f.repondre(self.adh, self.bulletin, "Neige\n à Gêve") + masque = self.f.repondre(self.pere, self.bulletin, "Bulletin masqué") + self.f.masquer_message(self.modo, masque) + + st, h, b = self.req(self.chemin, "mo1") + self.assertEqual(st, 200) + self.assertEqual(h["Content-Type"], "application/json; charset=utf-8") + self.assertEqual(h["Cache-Control"], "no-store") + self.assertIsNone(h["Set-Cookie"]) + d = json.loads(b) + self.assertEqual(d, {"n": 0, "titre": "Bulletin de la semaine du Vercors", "auteur": "Alex", + "extrait": "Neige à Gêve", "url": "/forum/t/%d" % self.bulletin}) + self.assertEqual(json.loads(self.req("/api/une.json")[2]), d) + self.assertEqual(self.req(d["url"])[0], 200) + + message = self.f.repondre(self.adh, self.bulletin, "x" * 181) + self.assertEqual(json.loads(self.req(self.chemin)[2])["extrait"], "x" * 179 + "…") + self.f.masquer_message(self.modo, message) + self.assertEqual(json.loads(self.req(self.chemin)[2]), d) + + def test_compte_des_sujets_publics_recents_sans_bulletin(self): + self.f.creer_sujet(self.adh, "Public", "Texte") + masque = self.f.creer_sujet(self.adh, "Masqué", "Texte") + self.f.masquer_sujet(self.modo, masque) + self.f.creer_sujet_station(self.prop, "geve", "En attente") + ancien = self.f.creer_sujet(self.adh, "Ancien", "Texte") + self.f.con.execute("UPDATE topics SET created_at=datetime('now', '-8 days') WHERE id=?", (ancien,)) + self.f.con.commit() + self.assertEqual(json.loads(self.req(self.chemin, "theo")[2]), {"n": 1}) + + class TestPrefixe(BaseHTTP): def setUp(self): super().setUp() diff --git a/maquettes/accueil-carte/index.html b/maquettes/accueil-carte/index.html index 7d14253..c08fa1f 100644 --- a/maquettes/accueil-carte/index.html +++ b/maquettes/accueil-carte/index.html @@ -300,6 +300,7 @@ a:focus-visible,button:focus-visible,input:focus-visible{outline:2px solid var(- .fb-une a{display:block;margin-top:2px;font-family:var(--titre);font-weight:600;font-size:17px;line-height:1.3;color:var(--roche);text-decoration:none} .fb-une a:hover{text-decoration:underline} .fb-une span{font-size:12.5px;color:var(--gris)} +.fb-une p{margin:4px 0 0;font-size:14px;overflow-wrap:anywhere} .fb-cta{display:block;margin:12px 16px 6px;padding:11px 14px;background:var(--sapin);color:#fff;text-align:center;font-size:13px;font-weight:600;letter-spacing:.07em;text-transform:uppercase;text-decoration:none;border:1px solid var(--sapin)} .fb-cta:hover{background:#17382b} .fb-co{margin:0 16px 12px;text-align:center;font-size:12.5px;color:var(--gris)} @@ -564,7 +565,7 @@ html[data-aff=acces]{--gris:#3a3f3c;--pierre:#b9b4a6} Toutes les stations ↓
Déjà un compte ? Se connecter avec Gastinel
Ces choix valent aussi pour la liste des stations, plus bas.
Déjà un compte ? Se connecter avec Gastinel
Déjà un compte ? Se connecter avec Gastinel
Ces choix valent aussi pour la liste des stations, plus bas.
Déjà un compte ? Se connecter avec Gastinel