35 lines
977 B
Python
35 lines
977 B
Python
from flask_login import current_user
|
|
from flask import request, redirect, url_for, flash, abort
|
|
|
|
from app.utils.render import render
|
|
from app.forms.forum import CommentForm
|
|
from app.models.forum import Forum
|
|
from app.models.topic import Topic
|
|
from app.models.thread import Thread
|
|
from app.models.comment import Comment
|
|
from app import app, db
|
|
|
|
|
|
@app.route('/forum/<forum:f>/<topicslug:t>', methods=['GET', 'POST'])
|
|
def forum_topic(f, t):
|
|
# Quick n' dirty workaround to converters
|
|
if f != t.forum:
|
|
abort(404)
|
|
|
|
form = CommentForm()
|
|
|
|
if form.validate_on_submit():
|
|
c = Comment(current_user, form.message.data, t.thread)
|
|
db.session.add(c)
|
|
db.session.commit()
|
|
flash('Message envoyé', 'ok')
|
|
# Redirect to empty the form
|
|
return redirect(url_for('forum_topic', f=f, t=t))
|
|
|
|
# Update views
|
|
t.views += 1
|
|
db.session.merge(t)
|
|
db.session.commit()
|
|
|
|
return render('/forum/topic.html', t=t, form=form)
|