diff --git a/nyaa/templates/comments.html b/nyaa/templates/comments.html new file mode 100644 index 00000000..9a0c5f18 --- /dev/null +++ b/nyaa/templates/comments.html @@ -0,0 +1,63 @@ +{% extends "layout.html" %} +{% block title %}All comments :: {{ config.SITE_NAME }}{% endblock %} +{% block metatags %} + +{% endblock %} + +{% block body %} +{% from "_formhelpers.html" import render_menu_with_button %} +{% from "_formhelpers.html" import render_field %} + + +{% if comments_query.items %} +
+
+

+ Total of {{ comments_query.total }} comments +

+
+ {% for comment in comments_query.items %} +
+
+ +
+
+ {{ comment.created_time.strftime('%Y-%m-%d %H:%M UTC') }} + {% if comment.edited_time %} + (edited) + {% endif %} + on torrent #{{comment.torrent_id}} {{ comment.torrent.display_name }} +
+
+ +
+
+
+
+ {# Escape newlines into html entities because CF strips blank newlines #} +
{{- comment.text | escape | replace('\r\n', '\n') | replace('\n', ' '|safe) -}}
+
+
+
+
+ + {% endfor %} +
+ +{% else %} +

No comments

+{% endif %} + +
+ {% from "bootstrap/pagination.html" import render_pagination %} + {{ render_pagination(comments_query) }} +
+ + +{% endblock %} + diff --git a/nyaa/templates/layout.html b/nyaa/templates/layout.html index 2c8c1e59..89bcc369 100644 --- a/nyaa/templates/layout.html +++ b/nyaa/templates/layout.html @@ -108,6 +108,7 @@
  • Reports
  • Log
  • Bans
  • +
  • Comments
  • {% endif %} diff --git a/nyaa/views/admin.py b/nyaa/views/admin.py index 27a58e3e..7a7ee7df 100644 --- a/nyaa/views/admin.py +++ b/nyaa/views/admin.py @@ -114,3 +114,23 @@ def view_reports(): return flask.render_template('reports.html', reports=reports, report_action=report_action) + + +@bp.route('/comments', endpoint='comments', methods=['GET']) +def view_comments(): + if not flask.g.user or not flask.g.user.is_moderator: + flask.abort(403) + + page_number = flask.request.args.get('p') + try: + page_number = max(1, int(page_number)) + except (ValueError, TypeError): + page_number = 1 + + comments_per_page = 50 + + comments_query = (models.Comment.query.filter() + .order_by(models.Comment.created_time.desc())) + comments_query = comments_query.paginate_faste(page_number, per_page=comments_per_page, step=5) + return flask.render_template('comments.html', + comments_query=comments_query)