diff --git a/app/forms/forum.py b/app/forms/forum.py index 7162415..2000283 100644 --- a/app/forms/forum.py +++ b/app/forms/forum.py @@ -21,3 +21,12 @@ class CommentForm(FlaskForm): class AnonymousCommentForm(CommentForm): pseudo = StringField('Pseudo', validators=[DataRequired(), vd.name_valid, vd.name_available]) + + +class CommentEditForm(CommentForm): + submit = SubmitField('Valider les modifications') + preview = SubmitField('Prévisualiser') + +class AnonymousCommentEditForm(CommentEditForm): + pseudo = StringField('Pseudo', + validators=[DataRequired(), vd.name_valid, vd.name_available]) diff --git a/app/routes/__init__.py b/app/routes/__init__.py index de98e92..ff0d0d9 100644 --- a/app/routes/__init__.py +++ b/app/routes/__init__.py @@ -5,3 +5,4 @@ from app.routes.account import login, account, notification from app.routes.admin import index, groups, account, trophies, forums from app.routes.forum import index, topic from app.routes.programs import index +from app.routes.posts import edit diff --git a/app/routes/account/account.py b/app/routes/account/account.py index 8a7e378..18fad37 100644 --- a/app/routes/account/account.py +++ b/app/routes/account/account.py @@ -130,7 +130,7 @@ def validation(): try: mail = request.args['email'] except Exception as e: - print("Error: {e}") + print(f"Error: {e}") abort(404) if current_user.is_authenticated: diff --git a/app/routes/posts/edit.py b/app/routes/posts/edit.py new file mode 100644 index 0000000..5b3c1b9 --- /dev/null +++ b/app/routes/posts/edit.py @@ -0,0 +1,34 @@ +from app import app, db +from app.models.post import Post +from app.utils.render import render +from app.forms.forum import CommentEditForm, AnonymousCommentEditForm +from flask import redirect, url_for, abort +from flask_login import login_required, current_user + +@app.route('/post/', methods=['GET','POST']) +# TODO: Allow guest edit of posts +@login_required +def edit_post(postid): + p = Post.query.filter_by(id=postid).first_or_404() + + # TODO: Check whether privileged user has access to board + if p.author != current_user and not current_user.priv("edit-posts"): + abort(403) + + if p.type == "comment": + form = CommentEditForm() + + if form.validate_on_submit(): + p.text = form.message.data + + if form.submit.data: + db.session.add(p) + db.session.commit() + + # TODO: Proper redirection + return redirect(url_for('index')) + + form.message.data = p.text + return render('forum/edit_comment.html', comment=p, form=form) + else: + abort(404) diff --git a/app/templates/forum/edit_comment.html b/app/templates/forum/edit_comment.html new file mode 100644 index 0000000..6127823 --- /dev/null +++ b/app/templates/forum/edit_comment.html @@ -0,0 +1,41 @@ +{% extends "base/base.html" %} +{% import "widgets/editor.html" as widget_editor %} +{% import "widgets/user.html" as widget_user %} + +{% block title %} +Forum de Planète Casio » Édition de commentaire +{% endblock %} + +{% block content %} +
+

Édition de commentaire

+ +

Commentaire actuel

+ + + + + +
{{ widget_user.profile(comment.author) }}
{{ comment.text }}
+ +
+

Nouveau commentaire

+
+ {{ form.hidden_tag() }} + + {% if form.pseudo %} + {{ form.pseudo.label }} + {{ form.pseudo }} + {% for error in form.pseudo.errors %} + {{ error }} + {% endfor %} + {% endif %} + + {{ widget_editor.text_editor(form.message, label=False) }} + +
{{ form.preview(class_='bg-ok') }}
+
{{ form.submit(class_='bg-ok') }}
+
+
+
+{% endblock %} diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html index 89052f0..d2b6914 100644 --- a/app/templates/forum/topic.html +++ b/app/templates/forum/topic.html @@ -29,7 +29,7 @@ Posté le {{ c.date_created|dyndate }} {% endif %} | # - | Modifier + | Modifier | Supprimer