Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions nyaa/templates/comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% extends "layout.html" %}
{% block title %}All comments :: {{ config.SITE_NAME }}{% endblock %}
{% block metatags %}
<meta property="og:description" content="Latest comments">
{% endblock %}

{% block body %}
{% from "_formhelpers.html" import render_menu_with_button %}
{% from "_formhelpers.html" import render_field %}


{% if comments_query.items %}
<div id="comments" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Total of {{ comments_query.total }} comments
</h3>
</div>
{% for comment in comments_query.items %}
<div class="panel panel-default comment-panel">
<div class="panel-body">
<div class="col-md-2">
<p>
<a class="text-{{ comment.user.userlevel_color }}" href="{{ url_for('users.view_user', user_name=comment.user.username) }}" data-toggle="tooltip" title="{{ comment.user.userlevel_str }}">{{ comment.user.username }}</a>
</p>
<img class="avatar" src="{{ comment.user.gravatar_url() }}" alt="{{ comment.user.userlevel_str }}">
</div>
<div class="col-md-10 comment">
<div class="row comment-details">
<small data-timestamp-swap data-timestamp="{{ comment.created_utc_timestamp|int }}">{{ comment.created_time.strftime('%Y-%m-%d %H:%M UTC') }}</small>
{% if comment.edited_time %}
<small data-timestamp-swap data-timestamp-title data-timestamp="{{ comment.edited_utc_timestamp }}" title="{{ comment.edited_time }}">(edited)</small>
{% endif %}
<small>on torrent <a href="{{ url_for('torrents.view', torrent_id=comment.torrent_id) }}">#{{comment.torrent_id}} <i>{{ comment.torrent.display_name }}</i></a></small>
<div class="comment-actions">
<form class="delete-comment-form" action="{{ url_for('torrents.delete_comment', torrent_id=comment.torrent_id, comment_id=comment.id) }}" method="POST">
<button name="submit" type="submit" class="btn btn-danger btn-xs" title="Delete">Delete</button>
</form>
</div>
</div>
<div class="row">
{# Escape newlines into html entities because CF strips blank newlines #}
<div markdown-text class="comment-content" id="torrent-comment{{ comment.id }}">{{- comment.text | escape | replace('\r\n', '\n') | replace('\n', '&#10;'|safe) -}}</div>
</div>
</div>
</div>
</div>

{% endfor %}
</div>

{% else %}
<h3>No comments</h3>
{% endif %}

<div class="center">
{% from "bootstrap/pagination.html" import render_pagination %}
{{ render_pagination(comments_query) }}
</div>


{% endblock %}
</div>
1 change: 1 addition & 0 deletions nyaa/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<li {% if request.path == url_for('admin.reports') %}class="active"{% endif %}><a href="{{ url_for('admin.reports') }}">Reports</a></li>
<li {% if request.path == url_for('admin.log') %}class="active"{% endif %}><a href="{{ url_for('admin.log') }}">Log</a></li>
<li {% if request.path == url_for('admin.bans') %}class="active"{% endif %}><a href="{{ url_for('admin.bans') }}">Bans</a></li>
<li {% if request.path == url_for('admin.comments') %}class="active"{% endif %}><a href="{{ url_for('admin.comments') }}">Comments</a></li>
</ul>
</li>
{% endif %}
Expand Down
20 changes: 20 additions & 0 deletions nyaa/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)