From 0c7474d8ba56628a1895c5c9b9126cd2b6d387bf Mon Sep 17 00:00:00 2001 From: Eldeberen Date: Sun, 21 Feb 2021 12:02:12 +0100 Subject: [PATCH] pclink: add handle for topics rewrite some handles in french --- app/utils/markdown_extensions/pclinks.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/utils/markdown_extensions/pclinks.py b/app/utils/markdown_extensions/pclinks.py index af01848..192e628 100644 --- a/app/utils/markdown_extensions/pclinks.py +++ b/app/utils/markdown_extensions/pclinks.py @@ -17,6 +17,7 @@ import xml.etree.ElementTree as etree from flask import url_for, render_template from app.utils.unicode_names import normalize from app.models.poll import Poll +from app.models.topic import Topic from app.models.user import Member class PCLinkExtension(Extension): @@ -43,8 +44,9 @@ class PCLinksInlineProcessor(InlineProcessor): super().__init__(pattern) self.config = config self.handles = { - 'poll': handlePoll, - 'user': handleUser, + 'membre': handleUser, 'user': handleUser, 'u': handleUser, + 'sondage': handlePoll, 'poll': handlePoll, + 'topic': handleTopic, 't': handleTopic, } def handleMatch(self, m, data): @@ -83,6 +85,24 @@ def handlePoll(content_id, context): html = html.replace('\n', '') # Needed to avoid lots of
due to etree return etree.fromstring(html) +def handleTopic(content_id, context): + try: + id = int(content_id) + except ValueError: + return "[ID du topic invalide]" + + topic = Topic.query.get(content_id) + + if topic is None: + return "[Topic non trouvé]" + + a = etree.Element('a') + a.text = topic.title + a.set('href', url_for('forum_topic', f=topic.forum, page=(topic,1))) + a.set('class', 'topic-link') + + return a + def handleUser(content_id, context): try: norm = normalize(content_id)