diff --git a/nyaa/models.py b/nyaa/models.py index 239da4a..9c91ef6 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -390,7 +390,7 @@ class Report(db.Model): __tablename__ = DB_TABLE_PREFIX + 'reports' id = db.Column(db.Integer, primary_key=True) - torrent = db.Column(db.Integer, db.ForeignKey( + torrent_id = db.Column(db.Integer, db.ForeignKey( DB_TABLE_PREFIX + 'torrents.id')) user_id = db.Column(db.Integer, db.ForeignKey( 'users.id')) @@ -398,8 +398,11 @@ class Report(db.Model): reason = db.Column(db.String(length=255), nullable=False) status = db.Column(ChoiceType(ReportStatus, impl=db.Integer()), nullable=False) - def __init__(self, torrent, user_id, reason): - self.torrent = torrent + user = db.relationship('User', uselist=False) + torrent = db.relationship('Torrent', uselist=False) + + def __init__(self, torrent_id, user_id, reason): + self.torrent_id = torrent_id self.user_id = user_id self.reason = reason self.status = ReportStatus.IN_REVIEW @@ -412,6 +415,10 @@ class Report(db.Model): ''' Returns a UTC POSIX timestamp, as seconds ''' return (self.created_time - UTC_EPOCH).total_seconds() + @classmethod + def not_reviewed(cls): + reports = cls.query.filter_by(status=0).all() + return reports # class Session(db.Model): # __tablename__ = 'sessions' diff --git a/nyaa/routes.py b/nyaa/routes.py index e1a2c14..4b03588 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -675,7 +675,7 @@ def submit_report(torrent_id): if flask.g.user is not None: current_user_id = flask.g.user.id report = models.Report( - torrent=torrent_id, + torrent_id=torrent_id, user_id=current_user_id, reason=report_reason) @@ -688,6 +688,17 @@ def submit_report(torrent_id): return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id)) +@app.route('/reports', methods=['GET']) +def view_reports(): + reports = models.Report.not_reviewed() + + if not flask.g.user or not flask.g.user.is_admin: + flask.abort(403) + + return flask.render_template('reports.html', + reports=reports) + + def _get_cached_torrent_file(torrent): # Note: obviously temporary cached_torrent = os.path.join(app.config['BASE_DIR'], diff --git a/nyaa/templates/layout.html b/nyaa/templates/layout.html index 46efe48..dcefdf8 100644 --- a/nyaa/templates/layout.html +++ b/nyaa/templates/layout.html @@ -72,6 +72,9 @@
  • RSS
  • {% if config.SITE_FLAVOR == 'nyaa' %}
  • Fap
  • + {% if g.user.is_admin %} +
  • Reports
  • + {% endif %} {% elif config.SITE_FLAVOR == 'sukebei' %}
  • Fun
  • {% endif %} diff --git a/nyaa/templates/reports.html b/nyaa/templates/reports.html new file mode 100644 index 0000000..91d7dcb --- /dev/null +++ b/nyaa/templates/reports.html @@ -0,0 +1,30 @@ +{% extends "layout.html" %} +{% block title %}Reports :: {{ config.SITE_NAME }}{% endblock %} +{% block body %} +{% from "_formhelpers.html" import render_field %} +
    + + + + + + + + + + + + + {% for report in reports %} + + + + + + + + {% endfor %} + +
    #Reported by:Torrent:Reason:Date:Action:
    {{ report.id }}{{ report.user.username }}{{ report.torrent.display_name }}{{ report.reason }}{{ report.created_time }}
    +
    +{% endblock %} diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index cf4b93a..bc98df5 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -133,7 +133,7 @@