From 3941a0b9b3cf63fc726a5861c5a28ae2941cc979 Mon Sep 17 00:00:00 2001 From: Anna-Maria Meriniemi Date: Mon, 4 Dec 2017 15:51:31 +0200 Subject: [PATCH] Quick and dirty comment list for moderators to look at (#421) --- nyaa/models.py | 5 +++ nyaa/templates/user.html | 1 + nyaa/templates/user_comments.html | 72 +++++++++++++++++++++++++++++++ nyaa/views/users.py | 27 ++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 nyaa/templates/user_comments.html diff --git a/nyaa/models.py b/nyaa/models.py index 2fa0116..8508b7b 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -441,6 +441,11 @@ class CommentBase(DeclarativeHelperBase): return db.relationship('User', uselist=False, back_populates=cls._table_prefix('comments'), lazy="joined") + @declarative.declared_attr + def torrent(cls): + return db.relationship(cls._flavor_prefix('Torrent'), uselist=False, + back_populates='comments', lazy="joined") + def __repr__(self): return '' % self.id diff --git a/nyaa/templates/user.html b/nyaa/templates/user.html index a1c3dba..587d24f 100644 --- a/nyaa/templates/user.html +++ b/nyaa/templates/user.html @@ -18,6 +18,7 @@
diff --git a/nyaa/templates/user_comments.html b/nyaa/templates/user_comments.html new file mode 100644 index 0000000..d76ae90 --- /dev/null +++ b/nyaa/templates/user_comments.html @@ -0,0 +1,72 @@ +{% extends "layout.html" %} +{% block title %}Comments made by {{ user.username }} :: {{ config.SITE_NAME }}{% endblock %} +{% block meta_image %}{{ user.gravatar_url() }}{% endblock %} +{% block metatags %} + +{% endblock %} + +{% block body %} +{% from "_formhelpers.html" import render_menu_with_button %} +{% from "_formhelpers.html" import render_field %} + +

+ {{ user.username }}'{{ '' if user.username[-1] == 's' else 's' }} comments +

+ +{% 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 }} + {#
+ {% if g.user.id == comment.user_id and not comment.editing_limit_exceeded %} + + {% endif %} + {% if g.user.is_moderator or g.user.id == comment.user_id %} +
+ +
+ {% endif %} +
#} +
+
+ {# 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/views/users.py b/nyaa/views/users.py index 7a95dd1..f60c220 100644 --- a/nyaa/views/users.py +++ b/nyaa/views/users.py @@ -226,6 +226,33 @@ def view_user(user_name): ipbanned=ipbanned) +@bp.route('/user//comments') +def view_user_comments(user_name): + user = models.User.by_username(user_name) + + if not user: + flask.abort(404) + + # Only moderators get to see all comments for now + 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 = 100 + + comments_query = (models.Comment.query.filter(models.Comment.user_id) + .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('user_comments.html', + comments_query=comments_query, + user=user) + + @bp.route('/user/activate/') def activate_user(payload): if app.config['MAINTENANCE_MODE']: