pclink: add handle for topics

rewrite some handles in french
This commit is contained in:
Eldeberen 2021-02-21 12:02:12 +01:00
parent cd8ce4f5bc
commit 0c7474d8ba
Signed by: Darks
GPG Key ID: 7515644268BE1433
1 changed files with 22 additions and 2 deletions

View File

@ -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 <br> 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)