From 1a9ebc19ed1e597857c2b9e14ecd73c39ca07664 Mon Sep 17 00:00:00 2001 From: Sn0wCrack Date: Sun, 14 May 2017 09:52:57 +1000 Subject: [PATCH] Added hard delete functionality --- nyaa/routes.py | 17 +++++++++++------ nyaa/templates/view.html | 6 +----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/nyaa/routes.py b/nyaa/routes.py index bc43e4c..cd97e56 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -591,12 +591,7 @@ def view_torrent(torrent_id): if torrent.filelist: files = json.loads(torrent.filelist.filelist_blob.decode('utf-8')) - if flask.g.user is not None and flask.g.user.is_admin: - comments = models.Comment.query.filter(models.Comment.torrent == torrent_id) - else: - comments = models.Comment.query.filter(models.Comment.torrent == torrent_id, - models.Comment.deleted == False) - + comments = models.Comment.query.filter_by(torrent=torrent_id) comment_count = comments.count() return flask.render_template('view.html', torrent=torrent, @@ -627,6 +622,16 @@ def submit_comment(torrent_id): return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id)) +@app.route('/view//delete_comment/') +def delete_comment(torrent_id, comment_id): + if flask.g.user is not None and flask.g.user.is_admin: + models.Comment.query.filter_by(id=comment_id).delete() + db.session.commit() + else: + flask.abort(403) + + return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id)) + @app.route('/view//edit', methods=['GET', 'POST']) def edit_torrent(torrent_id): diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index 658402e..0dc90a9 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -150,11 +150,7 @@ {% if g.user.is_admin %} - {% if not comment.deleted %} - - {% else %} - - {% endif %} + {% endif %}