From 5e98ca76d8cd12668dc2f36f923a76157ec7f991 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 4 Jan 2019 02:00:57 +0100 Subject: [PATCH] Correctly display newlines in diario page --- db.py | 4 ++++ templates/components/diarioentry.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/db.py b/db.py index 61a9a749..7c326dba 100644 --- a/db.py +++ b/db.py @@ -20,6 +20,7 @@ from telegram import User as TelegramUser import loldata from dirty import Dirty import query_discord_music +from flask import escape # Init the config reader import configparser @@ -685,6 +686,9 @@ class Diario(Base): def __str__(self): return f"{self.id} - {self.timestamp} - {self.author}: {self.text}" + def to_html(self): + return str(escape(self.text)).replace("\n", "
") + @staticmethod def import_from_json(file): import json diff --git a/templates/components/diarioentry.html b/templates/components/diarioentry.html index aba067b7..caa95470 100644 --- a/templates/components/diarioentry.html +++ b/templates/components/diarioentry.html @@ -1,7 +1,7 @@

- {{ entry.text }} + {{ entry.to_html() | safe }}

— {% if entry.author is not none %}{{ entry.author.royal.username }}{% else %}Anonimo{% endif %}, {{ entry.timestamp.strftime('%Y-%m-%d %H:%M:%S %Z') }} {% if entry.saver is not none and entry.saver != entry.author %}(salvato da {{ entry.saver.royal.username }}){% endif %}