Forum : page « Publier » (éditeur Markdown sûr, aperçu, brouillons)
- Bouton « Publier » dans l'en-tête (droit creer_sujet) ; /nouveau redirige vers /publier.
- /publier en pleine largeur : titre, station liée facultative, photos, « Me prévenir des
réponses » (enregistré seulement), emplacement « Catégorie » marqué bientôt.
- markdown_sur.py : convertisseur maison (HTML échappé d'abord, liens http(s) seulement,
titres, gras, italique, listes, code, paragraphes, tableaux pipe).
- posts.format ('texte' par défaut, 'md' depuis /publier) ; topics.station_liee et prevenir.
- Brouillons privés (table brouillons) : enregistrement auto ~1 s après la frappe
(apercu.js), bouton sans JS, page « Mes brouillons », suppression à la publication.
- Tests : tests/test_publier.py ; tests existants mis à jour pour /publier.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
7b7be84fdf
révision
c0d43e4e59
9 fichiers modifiés
+600
-30
Aucun fichier ne correspond à votre recherche
+62
-9
@@ -266,7 +266,7 @@ class Forum:
|
||||
raise Invalide("sujet introuvable")
|
||||
voit = self._peut(user, "voir_masques")
|
||||
msgs = self.con.execute(
|
||||
"SELECT p.id, p.topic_id, p.author_id, p.body, p.created_at, p.edited_at, p.hidden, p.ancien_body,"
|
||||
"SELECT p.id, p.topic_id, p.author_id, p.body, p.created_at, p.edited_at, p.hidden, p.ancien_body, p.format,"
|
||||
" u.display_name AS auteur FROM posts p JOIN users u ON u.id=p.author_id"
|
||||
" WHERE p.topic_id=? AND (p.hidden=0 OR ?) ORDER BY p.id", (topic_id, int(voit))).fetchall()
|
||||
return t, msgs
|
||||
@@ -301,26 +301,79 @@ class Forum:
|
||||
raise Invalide("%s vide ou trop long" % nom)
|
||||
return s
|
||||
|
||||
def _nouveau_sujet(self, user, titre, corps, ip, status="publie", station=None, prets=()):
|
||||
def _nouveau_sujet(self, user, titre, corps, ip, status="publie", station=None, prets=(), format_="texte",
|
||||
station_liee=None, prevenir=False):
|
||||
# Les fichiers sont deja valides ; aucune publication partielle si le
|
||||
# stockage echoue. Des fichiers sans reference peuvent rester sur disque.
|
||||
with self.con:
|
||||
cur = self.con.execute("INSERT INTO topics(title, author_id, status, station) VALUES (?, ?, ?, ?)",
|
||||
(titre, user["id"], status, station))
|
||||
post = self.con.execute("INSERT INTO posts(topic_id, author_id, body, ip) VALUES (?, ?, ?, ?)",
|
||||
(cur.lastrowid, user["id"], corps, ip))
|
||||
cur = self.con.execute("INSERT INTO topics(title, author_id, status, station, station_liee, prevenir) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
(titre, user["id"], status, station, station_liee, int(bool(prevenir))))
|
||||
post = self.con.execute("INSERT INTO posts(topic_id, author_id, body, ip, format) VALUES (?, ?, ?, ?, ?)",
|
||||
(cur.lastrowid, user["id"], corps, ip, format_))
|
||||
for nom, mime, propre in prets:
|
||||
empreinte, chemin = self._stocker(self.dossier_photos, mime, propre)
|
||||
self.con.execute("INSERT INTO attachments(post_id, filename, mime, size, sha256, stored_path) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
(post.lastrowid, nom, mime, len(propre), empreinte, chemin))
|
||||
return cur.lastrowid, post.lastrowid
|
||||
|
||||
def creer_sujet(self, user, titre, corps, ip=None, fichiers=()):
|
||||
"""Adherents et proprietaires ; photos validees avant creation du sujet."""
|
||||
def creer_sujet(self, user, titre, corps, ip=None, fichiers=(), format_="texte", station_liee="", prevenir=False, brouillon=None):
|
||||
"""Adherents et proprietaires ; photos validees avant creation du sujet.
|
||||
Page « Publier » : format 'md', station citée facultative, brouillon supprimé après publication."""
|
||||
self._exiger(user, "creer_sujet")
|
||||
titre, corps = self._texte(titre, TITRE_MAX, "titre"), self._texte(corps, CORPS_MAX, "message")
|
||||
if format_ not in ("texte", "md"):
|
||||
raise Invalide("format inconnu")
|
||||
station_liee = self._station_facultative(station_liee)
|
||||
if brouillon:
|
||||
self.brouillon(user, brouillon) # le brouillon doit être à l'auteur
|
||||
prets = self._preparer_photos(list(fichiers), illimite=self._peut(user, "photos_illimitees")) if fichiers else []
|
||||
return self._nouveau_sujet(user, titre, corps, ip, prets=prets)[0]
|
||||
tid = self._nouveau_sujet(user, titre, corps, ip, prets=prets, format_=format_,
|
||||
station_liee=station_liee or None, prevenir=prevenir)[0]
|
||||
if brouillon:
|
||||
self.supprimer_brouillon(user, brouillon)
|
||||
return tid
|
||||
|
||||
# --- brouillons (page « Publier ») ---------------------------------------
|
||||
def _station_facultative(self, station):
|
||||
station = (station or "").strip()
|
||||
if station and station not in self.stations:
|
||||
raise Invalide("station inconnue")
|
||||
return station
|
||||
|
||||
def brouillon(self, user, brouillon_id):
|
||||
"""Brouillon de l'auteur ; celui d'un autre est introuvable."""
|
||||
if user is None:
|
||||
raise Refus("connexion requise")
|
||||
b = self.con.execute("SELECT * FROM brouillons WHERE id=? AND user_id=?", (int(brouillon_id), user["id"])).fetchone()
|
||||
if b is None:
|
||||
raise Invalide("brouillon introuvable")
|
||||
return b
|
||||
|
||||
def brouillons(self, user):
|
||||
if user is None:
|
||||
raise Refus("connexion requise")
|
||||
return self.con.execute("SELECT * FROM brouillons WHERE user_id=? ORDER BY maj DESC, id DESC", (user["id"],)).fetchall()
|
||||
|
||||
def enregistrer_brouillon(self, user, brouillon_id, titre, corps, station="", prevenir=False):
|
||||
"""Crée ou met à jour un brouillon de l'auteur ; retourne (id, maj)."""
|
||||
self._exiger(user, "creer_sujet")
|
||||
titre, corps = (titre or "")[:TITRE_MAX], (corps or "")[:CORPS_MAX]
|
||||
station = self._station_facultative(station)
|
||||
with self.con:
|
||||
if brouillon_id:
|
||||
self.brouillon(user, brouillon_id)
|
||||
self.con.execute("UPDATE brouillons SET titre=?, corps=?, station=?, prevenir=?, maj=datetime('now') WHERE id=? AND user_id=?",
|
||||
(titre, corps, station, int(bool(prevenir)), int(brouillon_id), user["id"]))
|
||||
bid = int(brouillon_id)
|
||||
else:
|
||||
bid = self.con.execute("INSERT INTO brouillons(user_id, titre, corps, station, prevenir) VALUES (?, ?, ?, ?, ?)",
|
||||
(user["id"], titre, corps, station, int(bool(prevenir)))).lastrowid
|
||||
return bid, self.brouillon(user, bid)["maj"]
|
||||
|
||||
def supprimer_brouillon(self, user, brouillon_id):
|
||||
self.brouillon(user, brouillon_id)
|
||||
with self.con:
|
||||
self.con.execute("DELETE FROM brouillons WHERE id=? AND user_id=?", (int(brouillon_id), user["id"]))
|
||||
|
||||
def creer_sujet_station(self, user, station, corps, ip=None):
|
||||
"""Propriétaire de station : un seul sujet pour sa station, titre préconfiguré, à valider."""
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur