post edition: added redirection to topic (#49)

Beware that the urlparse method may return unsafe results… IDK
This commit is contained in:
Darks 2020-09-24 23:25:25 +02:00
parent 67c3ebba42
commit 5253f8ec8f
Signed by: Darks
GPG Key ID: 7515644268BE1433
2 changed files with 8 additions and 4 deletions

View File

@ -2,13 +2,18 @@ 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 urllib.parse import urlparse
from flask import redirect, url_for, abort, request
from flask_login import login_required, current_user
@app.route('/post/<int:postid>', methods=['GET','POST'])
# TODO: Allow guest edit of posts
@login_required
def edit_post(postid):
# TODO: Maybe not safe
referrer = urlparse(request.args.get('r', default = '/', type = str)).path
print(referrer)
p = Post.query.filter_by(id=postid).first_or_404()
# TODO: Check whether privileged user has access to board
@ -25,8 +30,7 @@ def edit_post(postid):
db.session.add(p)
db.session.commit()
# TODO: Proper redirection
return redirect(url_for('index'))
return redirect(referrer)
form.message.data = p.text
return render('forum/edit_comment.html', comment=p, form=form)

View File

@ -30,7 +30,7 @@
Posté le {{ c.date_created|dyndate }}
{% endif %}
| <a href="{{ url_for('forum_topic', f=t.forum, page=(t,comments.page), _anchor=c.id) }}">#</a>
| <a href="{{ url_for('edit_post', postid=c.id) }}">Modifier</a>
| <a href="{{ url_for('edit_post', postid=c.id, r=request.path) }}">Modifier</a>
| <a href="#">Supprimer</a>
</div>
<!--<hr>-->