Forum : sujets de station d'office, lien carte, pastille « Nouveau », bouton Trier

- un sujet publié par station (ordre de la carte, grille compacte), repris par
  le propriétaire de station avec sa présentation ;
- encadré station dans le sujet : dernière mesure (< 2 h) et lien vers la carte ;
- pastille « Nouveau » par compte (table lectures), sans cookie de suivi ;
- tri : activité, création, longueur, avec/sans photos (fenêtre sans JavaScript).
74 tests OK. En essai sur :32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
Théo GastineletClaude Opus 5.5 a révisé 2026-11-05 23:29:57 +01:00
1 Parent fbae20bc05
révision 08775242f5
4 fichiers modifiés
+247 -22

Aucun fichier ne correspond à votre recherche

+59 -8
Voir le fichier
@@ -203,16 +203,56 @@ class Forum:
return self._peut(user, "valider_sujet") or (user is not None and t["author_id"] == user["id"])
return True
def sujets(self, user):
"""Sujets : épinglés d'abord (le Bulletin en tête), puis les plus récents."""
TRIS = ("activite", "recents", "anciens", "longs", "courts")
def sujets(self, user, tri="activite", media=""):
"""Sujets : épinglés d'abord (le Bulletin en tête), puis selon `tri` :
activite (dernier message), recents / anciens (création), longs / courts (taille du premier message).
`media` : « avec » ou « sans » photos. Pour un compte, `nouveau` = messages pas encore lus."""
voit = self._peut(user, "voir_masques")
ordre = {"activite": "COALESCE(dernier, 0) DESC, t.id DESC", "recents": "t.id DESC", "anciens": "t.id ASC",
"longs": "COALESCE(taille, 0) DESC, t.id DESC", "courts": "COALESCE(taille, 0) ASC, t.id DESC"}.get(tri, "COALESCE(dernier, 0) DESC, t.id DESC")
uid = user["id"] if user is not None else 0
rows = self.con.execute(
"SELECT t.*, u.display_name AS auteur,"
"SELECT t.*, u.display_name AS auteur, u.hub_id AS auteur_hub,"
" (SELECT COUNT(*) FROM posts p WHERE p.topic_id=t.id AND (p.hidden=0 OR ?)) AS n,"
" (SELECT MAX(p.id) FROM posts p WHERE p.topic_id=t.id AND p.hidden=0) AS dernier"
" (SELECT MAX(p.id) FROM posts p WHERE p.topic_id=t.id AND p.hidden=0) AS dernier,"
" (SELECT LENGTH(p.body) FROM posts p WHERE p.topic_id=t.id AND p.hidden=0 ORDER BY p.id LIMIT 1) AS taille,"
" EXISTS(SELECT 1 FROM attachments a JOIN posts p ON p.id=a.post_id WHERE p.topic_id=t.id AND p.hidden=0) AS media,"
" EXISTS(SELECT 1 FROM posts p JOIN users me ON me.id=? WHERE p.topic_id=t.id AND p.hidden=0 AND p.author_id<>me.id"
" AND p.created_at >= me.created_at"
" AND p.id > COALESCE((SELECT l.dernier_post FROM lectures l WHERE l.user_id=me.id AND l.topic_id=t.id), 0)) AS nouveau"
" FROM topics t JOIN users u ON u.id=t.author_id"
" ORDER BY t.fixed DESC, t.pinned DESC, t.pin_pos, COALESCE(dernier, 0) DESC, t.id DESC", (int(voit),)).fetchall()
return [r for r in rows if self._visible(user, r)]
" ORDER BY t.fixed DESC, t.pinned DESC, t.pin_pos, " + ordre, (int(voit), uid)).fetchall()
rows = [r for r in rows if self._visible(user, r)]
if media in ("avec", "sans"):
rows = [r for r in rows if bool(r["media"]) == (media == "avec")]
return rows
def noter_lecture(self, user, topic_id, dernier_post):
"""Le compte a vu le sujet jusqu'à ce message (pas de suivi pour les visiteurs)."""
if user is None or not dernier_post:
return
self.con.execute("INSERT INTO lectures(user_id, topic_id, dernier_post) VALUES (?, ?, ?)"
" ON CONFLICT(user_id, topic_id) DO UPDATE SET dernier_post=MAX(dernier_post, excluded.dernier_post)",
(user["id"], topic_id, dernier_post))
self.con.commit()
def creer_sujets_stations(self):
"""Un sujet publié par station connue (auteur : compte technique), même sans message.
Le propriétaire de la station le reprend en publiant sa présentation. Retourne le nombre créé."""
sid = self.con.execute("SELECT id FROM users WHERE hub_id=?", (db.SYSTEME,)).fetchone()[0]
n = 0
for station, nom in self.stations.items():
if self.con.execute("SELECT 1 FROM topics WHERE station=? AND status<>'refuse'", (station,)).fetchone():
continue
self.con.execute("INSERT INTO topics(title, author_id, status, station) VALUES (?, ?, 'publie', ?)",
("Station · " + nom, sid, station))
n += 1
self.con.commit()
if n:
self.version += 1
return n
def sujet(self, user, topic_id):
"""Retourne (sujet, messages). Invisible = introuvable."""
@@ -282,10 +322,21 @@ class Forum:
self._exiger(user, "creer_sujet_station")
if station not in self.stations_de(user):
raise Refus("ce n'est pas votre station")
if self.con.execute("SELECT 1 FROM topics WHERE station=? AND status<>'refuse'", (station,)).fetchone():
corps = self._texte(corps, CORPS_MAX, "message")
t = self.con.execute("SELECT t.id, u.hub_id FROM topics t JOIN users u ON u.id=t.author_id"
" WHERE t.station=? AND t.status<>'refuse'", (station,)).fetchone()
if t is not None and t["hub_id"] == db.SYSTEME:
# Sujet créé d'office : le propriétaire (rôle déjà validé) le reprend avec sa présentation.
with self.con:
self.con.execute("UPDATE topics SET author_id=? WHERE id=?", (user["id"], t["id"]))
self.con.execute("INSERT INTO posts(topic_id, author_id, body, ip) VALUES (?, ?, ?, ?)",
(t["id"], user["id"], corps, ip))
self.version += 1
return t["id"]
if t is not None:
raise Invalide("cette station a déjà son sujet")
titre = "Station · " + self.stations.get(station, station)
return self._nouveau_sujet(user, titre, self._texte(corps, CORPS_MAX, "message"), ip, "en_attente", station)[0]
return self._nouveau_sujet(user, titre, corps, ip, "en_attente", station)[0]
def valider_sujet(self, user, topic_id, accepte=True):
self._exiger(user, "valider_sujet")