mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 19:30:00 +00:00
Move posting comments to view_torrent to fix displaying form errors.
This commit is contained in:
parent
b7144f80f9
commit
3fc347d049
|
@ -571,8 +571,11 @@ def upload():
|
|||
return flask.render_template('upload.html', upload_form=upload_form), status_code
|
||||
|
||||
|
||||
@app.route('/view/<int:torrent_id>')
|
||||
@app.route('/view/<int:torrent_id>', methods=['GET', 'POST'])
|
||||
def view_torrent(torrent_id):
|
||||
if flask.request.method == 'POST':
|
||||
torrent = models.Torrent.by_id(torrent_id)
|
||||
else:
|
||||
torrent = models.Torrent.query \
|
||||
.options(joinedload('filelist'),
|
||||
joinedload('comments')) \
|
||||
|
@ -585,36 +588,16 @@ def view_torrent(torrent_id):
|
|||
if torrent.deleted and not (flask.g.user and flask.g.user.is_moderator):
|
||||
flask.abort(404)
|
||||
|
||||
# Only allow owners and admins to edit torrents
|
||||
can_edit = flask.g.user and (flask.g.user is torrent.user or flask.g.user.is_moderator)
|
||||
|
||||
files = None
|
||||
if torrent.filelist:
|
||||
files = json.loads(torrent.filelist.filelist_blob.decode('utf-8'))
|
||||
|
||||
comment_form = None
|
||||
if flask.g.user:
|
||||
comment_form = forms.CommentForm()
|
||||
|
||||
return flask.render_template('view.html', torrent=torrent,
|
||||
files=files,
|
||||
comment_form=comment_form,
|
||||
comments=torrent.comments,
|
||||
can_edit=can_edit)
|
||||
|
||||
|
||||
@app.route('/view/<int:torrent_id>/comment', methods=['POST'])
|
||||
def submit_comment(torrent_id):
|
||||
if flask.request.method == 'POST':
|
||||
if not flask.g.user:
|
||||
flask.abort(403)
|
||||
|
||||
torrent = models.Torrent.by_id(torrent_id)
|
||||
if not torrent:
|
||||
flask.abort(404)
|
||||
|
||||
form = forms.CommentForm(flask.request.form)
|
||||
if form.validate():
|
||||
comment_text = (form.comment.data or '').strip()
|
||||
if comment_form.validate():
|
||||
comment_text = (comment_form.comment.data or '').strip()
|
||||
|
||||
comment = models.Comment(
|
||||
torrent_id=torrent_id,
|
||||
|
@ -624,8 +607,23 @@ def submit_comment(torrent_id):
|
|||
db.session.add(comment)
|
||||
db.session.commit()
|
||||
|
||||
flask.flash('Comment successfully posted.', 'success')
|
||||
|
||||
return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id))
|
||||
|
||||
# Only allow owners and admins to edit torrents
|
||||
can_edit = flask.g.user and (flask.g.user is torrent.user or flask.g.user.is_moderator)
|
||||
|
||||
files = None
|
||||
if torrent.filelist:
|
||||
files = json.loads(torrent.filelist.filelist_blob.decode('utf-8'))
|
||||
|
||||
return flask.render_template('view.html', torrent=torrent,
|
||||
files=files,
|
||||
comment_form=comment_form,
|
||||
comments=torrent.comments,
|
||||
can_edit=can_edit)
|
||||
|
||||
|
||||
@app.route('/view/<int:torrent_id>/comment/<int:comment_id>/delete', methods=['POST'])
|
||||
def delete_comment(torrent_id, comment_id):
|
||||
|
|
|
@ -176,7 +176,7 @@
|
|||
</script>
|
||||
{% endfor %}
|
||||
{% if comment_form %}
|
||||
<form action="{{ url_for('submit_comment', torrent_id=torrent.id) }}" method="POST" class="comment-box">
|
||||
<form class="comment-box" method="POST">
|
||||
{{ comment_form.csrf_token }}
|
||||
{{ render_field(comment_form.comment, class_='form-control') }}
|
||||
<input type="submit" value="Submit" class="btn btn-success btn-sm">
|
||||
|
|
Loading…
Reference in a new issue