pclink: add handle for topics
rewrite some handles in french
This commit is contained in:
parent
cd8ce4f5bc
commit
0c7474d8ba
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue