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 ↓
Forum
-
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
+
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
Rejoindre la discussion →

Déjà un compte ? Se connecter avec Gastinel

L'écosystème Gastinel. Un compte pour le forum, vos favoris et toutes nos applications. Sans publicité, une alternative aux GAFAM.
@@ -578,7 +579,7 @@ html[data-aff=acces]{--gris:#3a3f3c;--pierre:#b9b4a6}

Ces choix valent aussi pour la liste des stations, plus bas.

Forum
-
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
+
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
Rejoindre la discussion →

Déjà un compte ? Se connecter avec Gastinel

L'écosystème Gastinel. Un compte pour le forum, vos favoris et toutes nos applications. Sans publicité, une alternative aux GAFAM.
@@ -700,6 +701,7 @@ const dec = s => L === 'en' ? s : s.replace('.', ','); // les noms de stations et de lieux ne sont jamais traduits. const I18N = { fr: { + 'fb.auteur': nom => `par ${nom}`, 'fb.compte': n => `${n} ${n === 1 ? 'sujet' : 'sujets'} sur 7 jours`, moment: h => h < 5 ? 'Cette nuit' : h < 12 ? 'Ce matin' : h < 18 ? 'Cet après-midi' : h < 23 ? 'Ce soir' : 'Cette nuit', 'phrase.charge': 'Relevés en cours de chargement…', 'reseau.n': n => `${n} stations dans le massif`, @@ -757,6 +759,7 @@ const I18N = { 'record.label': 'Highlight', 'record.auto': 'By season', 'record.froid': 'Coldest', 'record.chaud': 'Warmest', 'record.vent': 'Windiest', 'record.pluie': 'Wettest', retour: '← Whole massif', 'direct.attente': 'Loading readings…', suite: 'All stations ↓', 'fb.titre': 'Forum', 'fb.une': 'Featured · Weekly summary', 'fb.lien': 'The weekly summary will appear here', 'fb.cta': 'Join the discussion →', + 'fb.auteur': nom => `by ${nom}`, 'fb.compte': n => `${n} ${n === 1 ? 'topic' : 'topics'} in 7 days`, 'fb.co': 'Already have an account?', 'fb.connexion': 'Sign in with Gastinel', 'fb.bas': 'The Gastinel ecosystem. One account for the forum, your favourites and all our apps. No ads, an alternative to Big Tech.', 'sous-carte': 'Contour lines every 100 m · zoom: mouse wheel (PC) or two fingers (phone)', @@ -836,6 +839,7 @@ const I18N = { 'record.label': 'Hervorheben', 'record.auto': 'Je nach Jahreszeit', 'record.froid': 'Am kältesten', 'record.chaud': 'Am wärmsten', 'record.vent': 'Am windigsten', 'record.pluie': 'Am meisten Regen', retour: '← Ganzes Massiv', 'direct.attente': 'Messwerte werden geladen…', suite: 'Alle Stationen ↓', 'fb.titre': 'Forum', 'fb.une': 'Im Fokus · Wochenrückblick', 'fb.lien': 'Hier erscheint der Wochenrückblick', 'fb.cta': 'Mitdiskutieren →', + 'fb.auteur': nom => `von ${nom}`, 'fb.compte': n => `${n} ${n === 1 ? 'Thema' : 'Themen'} in 7 Tagen`, 'fb.co': 'Schon ein Konto?', 'fb.connexion': 'Mit Gastinel anmelden', 'fb.bas': 'Das Gastinel-Ökosystem. Ein Konto für das Forum, Ihre Favoriten und alle unsere Apps. Ohne Werbung, eine Alternative zu den großen Tech-Konzernen.', 'sous-carte': 'Höhenlinien alle 100 m · Zoom: Mausrad (PC) oder zwei Finger (Handy)', @@ -1914,12 +1918,28 @@ btnLecture.addEventListener('click', () => { btnLecture.textContent = '❚❚'; btnLecture.setAttribute('aria-label', t('lecture.pause')); lectureId = setInterval(() => { curseur.value = Math.min(N, +curseur.value + 1); poserTemps(); if (+curseur.value >= N) arreterLecture(); }, 260); }); -(FORUM_OUVERT ? fetch('data/forum-une.json?' + Math.floor(Date.now() / 300000)).then(r => r.ok ? r.json() : null).then(u => { - if (!u || !u.titre) return; - document.querySelectorAll('[data-une]').forEach(a => { a.textContent = u.titre; if (typeof u.url === 'string' && u.url.startsWith('/forum/') && !u.url.startsWith('//')) a.href = u.url; }); - document.querySelectorAll('[data-auteur]').forEach(e => { e.textContent = u.auteur ? 'par ' + u.auteur : ''; }); - if (u.n) document.querySelectorAll('[data-n]').forEach(e => { e.textContent = u.n + (u.n > 1 ? ' sujets' : ' sujet') + ' cette semaine'; }); -}).catch(() => {}) : 0); +let uneForum = null; +function afficherUneForum(){ + if (!uneForum) return; + const {titre, auteur, extrait, url, n} = uneForum; + if (Number.isSafeInteger(n) && n > 0) { + document.querySelectorAll('[data-n]').forEach(e => { e.textContent = t('fb.compte', n); }); + } + if (typeof titre !== 'string' || !titre || typeof url !== 'string' || !/^\/forum\/t\/[1-9][0-9]*$/.test(url)) return; + document.querySelectorAll('[data-une]').forEach(a => { a.textContent = titre; a.href = url; }); + if (typeof auteur === 'string' && auteur) { + document.querySelectorAll('[data-auteur]').forEach(e => { e.textContent = t('fb.auteur', auteur); }); + } + if (typeof extrait === 'string' && extrait) { + document.querySelectorAll('[data-extrait]').forEach(e => { e.textContent = extrait; e.hidden = false; }); + } +} +if (FORUM_OUVERT) { + fetch('/forum/api/une.json', {credentials: 'omit'}).then(r => r.ok ? r.json() : null).then(u => { + uneForum = u; + afficherUneForum(); + }).catch(() => {}); +} remplirBilan(); // le bilan est déplié dès l'arrivée function apresDonnees(){ chargerSeries(); if (TEMPS != null) { snapshotLive(); appliquerTemps(); } } const selRecord = document.getElementById('record'); @@ -2356,7 +2376,7 @@ dlgPrm.addEventListener('change', ev => { }); // après un changement de langue ou d'affichage : textes refaits, étiquettes remesurées, puces replacées function apresReglage(){ - traduirePage(); formatsDates(); forumTextes(); majAlt(); majTempsTxt(); majDate(); afficherDirect(); + traduirePage(); formatsDates(); forumTextes(); afficherUneForum(); majAlt(); majTempsTxt(); majDate(); afficherDirect(); btnLecture.setAttribute('aria-label', t(lectureId ? 'lecture.pause' : 'lecture.rejouer')); plein.setAttribute('aria-label', t('plein.aria')); plein.querySelector('.plein-ferme').textContent = t('plein.retour'); phraseDuJour(); listeStations(); coupe(); diff --git a/maquettes/accueil-carte/modele.html b/maquettes/accueil-carte/modele.html index ce555ab..f98bf1d 100644 --- a/maquettes/accueil-carte/modele.html +++ b/maquettes/accueil-carte/modele.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 ↓
Forum
-
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
+
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
Rejoindre la discussion →

Déjà un compte ? Se connecter avec Gastinel

L'écosystème Gastinel. Un compte pour le forum, vos favoris et toutes nos applications. Sans publicité, une alternative aux GAFAM.
@@ -578,7 +579,7 @@ html[data-aff=acces]{--gris:#3a3f3c;--pierre:#b9b4a6}

Ces choix valent aussi pour la liste des stations, plus bas.

Forum
-
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
+
À la une · Récapitulatif de la semaineLe récapitulatif de la semaine arrive ici
Rejoindre la discussion →

Déjà un compte ? Se connecter avec Gastinel

L'écosystème Gastinel. Un compte pour le forum, vos favoris et toutes nos applications. Sans publicité, une alternative aux GAFAM.
@@ -700,6 +701,7 @@ const dec = s => L === 'en' ? s : s.replace('.', ','); // les noms de stations et de lieux ne sont jamais traduits. const I18N = { fr: { + 'fb.auteur': nom => `par ${nom}`, 'fb.compte': n => `${n} ${n === 1 ? 'sujet' : 'sujets'} sur 7 jours`, moment: h => h < 5 ? 'Cette nuit' : h < 12 ? 'Ce matin' : h < 18 ? 'Cet après-midi' : h < 23 ? 'Ce soir' : 'Cette nuit', 'phrase.charge': 'Relevés en cours de chargement…', 'reseau.n': n => `${n} stations dans le massif`, @@ -757,6 +759,7 @@ const I18N = { 'record.label': 'Highlight', 'record.auto': 'By season', 'record.froid': 'Coldest', 'record.chaud': 'Warmest', 'record.vent': 'Windiest', 'record.pluie': 'Wettest', retour: '← Whole massif', 'direct.attente': 'Loading readings…', suite: 'All stations ↓', 'fb.titre': 'Forum', 'fb.une': 'Featured · Weekly summary', 'fb.lien': 'The weekly summary will appear here', 'fb.cta': 'Join the discussion →', + 'fb.auteur': nom => `by ${nom}`, 'fb.compte': n => `${n} ${n === 1 ? 'topic' : 'topics'} in 7 days`, 'fb.co': 'Already have an account?', 'fb.connexion': 'Sign in with Gastinel', 'fb.bas': 'The Gastinel ecosystem. One account for the forum, your favourites and all our apps. No ads, an alternative to Big Tech.', 'sous-carte': 'Contour lines every 100 m · zoom: mouse wheel (PC) or two fingers (phone)', @@ -836,6 +839,7 @@ const I18N = { 'record.label': 'Hervorheben', 'record.auto': 'Je nach Jahreszeit', 'record.froid': 'Am kältesten', 'record.chaud': 'Am wärmsten', 'record.vent': 'Am windigsten', 'record.pluie': 'Am meisten Regen', retour: '← Ganzes Massiv', 'direct.attente': 'Messwerte werden geladen…', suite: 'Alle Stationen ↓', 'fb.titre': 'Forum', 'fb.une': 'Im Fokus · Wochenrückblick', 'fb.lien': 'Hier erscheint der Wochenrückblick', 'fb.cta': 'Mitdiskutieren →', + 'fb.auteur': nom => `von ${nom}`, 'fb.compte': n => `${n} ${n === 1 ? 'Thema' : 'Themen'} in 7 Tagen`, 'fb.co': 'Schon ein Konto?', 'fb.connexion': 'Mit Gastinel anmelden', 'fb.bas': 'Das Gastinel-Ökosystem. Ein Konto für das Forum, Ihre Favoriten und alle unsere Apps. Ohne Werbung, eine Alternative zu den großen Tech-Konzernen.', 'sous-carte': 'Höhenlinien alle 100 m · Zoom: Mausrad (PC) oder zwei Finger (Handy)', @@ -1914,12 +1918,28 @@ btnLecture.addEventListener('click', () => { btnLecture.textContent = '❚❚'; btnLecture.setAttribute('aria-label', t('lecture.pause')); lectureId = setInterval(() => { curseur.value = Math.min(N, +curseur.value + 1); poserTemps(); if (+curseur.value >= N) arreterLecture(); }, 260); }); -(FORUM_OUVERT ? fetch('data/forum-une.json?' + Math.floor(Date.now() / 300000)).then(r => r.ok ? r.json() : null).then(u => { - if (!u || !u.titre) return; - document.querySelectorAll('[data-une]').forEach(a => { a.textContent = u.titre; if (typeof u.url === 'string' && u.url.startsWith('/forum/') && !u.url.startsWith('//')) a.href = u.url; }); - document.querySelectorAll('[data-auteur]').forEach(e => { e.textContent = u.auteur ? 'par ' + u.auteur : ''; }); - if (u.n) document.querySelectorAll('[data-n]').forEach(e => { e.textContent = u.n + (u.n > 1 ? ' sujets' : ' sujet') + ' cette semaine'; }); -}).catch(() => {}) : 0); +let uneForum = null; +function afficherUneForum(){ + if (!uneForum) return; + const {titre, auteur, extrait, url, n} = uneForum; + if (Number.isSafeInteger(n) && n > 0) { + document.querySelectorAll('[data-n]').forEach(e => { e.textContent = t('fb.compte', n); }); + } + if (typeof titre !== 'string' || !titre || typeof url !== 'string' || !/^\/forum\/t\/[1-9][0-9]*$/.test(url)) return; + document.querySelectorAll('[data-une]').forEach(a => { a.textContent = titre; a.href = url; }); + if (typeof auteur === 'string' && auteur) { + document.querySelectorAll('[data-auteur]').forEach(e => { e.textContent = t('fb.auteur', auteur); }); + } + if (typeof extrait === 'string' && extrait) { + document.querySelectorAll('[data-extrait]').forEach(e => { e.textContent = extrait; e.hidden = false; }); + } +} +if (FORUM_OUVERT) { + fetch('/forum/api/une.json', {credentials: 'omit'}).then(r => r.ok ? r.json() : null).then(u => { + uneForum = u; + afficherUneForum(); + }).catch(() => {}); +} remplirBilan(); // le bilan est déplié dès l'arrivée function apresDonnees(){ chargerSeries(); if (TEMPS != null) { snapshotLive(); appliquerTemps(); } } const selRecord = document.getElementById('record'); @@ -2356,7 +2376,7 @@ dlgPrm.addEventListener('change', ev => { }); // après un changement de langue ou d'affichage : textes refaits, étiquettes remesurées, puces replacées function apresReglage(){ - traduirePage(); formatsDates(); forumTextes(); majAlt(); majTempsTxt(); majDate(); afficherDirect(); + traduirePage(); formatsDates(); forumTextes(); afficherUneForum(); majAlt(); majTempsTxt(); majDate(); afficherDirect(); btnLecture.setAttribute('aria-label', t(lectureId ? 'lecture.pause' : 'lecture.rejouer')); plein.setAttribute('aria-label', t('plein.aria')); plein.querySelector('.plein-ferme').textContent = t('plein.retour'); phraseDuJour(); listeStations(); coupe();