mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 14:10:00 +00:00
Usage of WTForms for report action
This commit is contained in:
parent
73c84ce5ec
commit
ec0f8000d7
|
@ -6,7 +6,7 @@ import os
|
||||||
import re
|
import re
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_wtf.file import FileField, FileRequired
|
from flask_wtf.file import FileField, FileRequired
|
||||||
from wtforms import StringField, PasswordField, BooleanField, TextAreaField, SelectField
|
from wtforms import StringField, PasswordField, BooleanField, TextAreaField, SelectField, HiddenField
|
||||||
from wtforms.validators import DataRequired, Optional, Email, Length, EqualTo, ValidationError
|
from wtforms.validators import DataRequired, Optional, Email, Length, EqualTo, ValidationError
|
||||||
from wtforms.validators import Regexp
|
from wtforms.validators import Regexp
|
||||||
|
|
||||||
|
@ -287,6 +287,12 @@ class ReportForm(FlaskForm):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class ReportActionForm(FlaskForm):
|
||||||
|
action = SelectField(choices=[('close', 'Close'), ('hide', 'Hide'), ('delete', 'Delete')])
|
||||||
|
torrent = HiddenField()
|
||||||
|
report = HiddenField()
|
||||||
|
|
||||||
|
|
||||||
def _validate_trackers(torrent_dict, tracker_to_check_for=None):
|
def _validate_trackers(torrent_dict, tracker_to_check_for=None):
|
||||||
announce = torrent_dict.get('announce')
|
announce = torrent_dict.get('announce')
|
||||||
announce_string = _validate_bytes(announce, 'announce', 'utf-8')
|
announce_string = _validate_bytes(announce, 'announce', 'utf-8')
|
||||||
|
|
|
@ -693,30 +693,35 @@ def view_reports():
|
||||||
|
|
||||||
page = flask.request.args.get('p', flask.request.args.get('offset', 1, int), int)
|
page = flask.request.args.get('p', flask.request.args.get('offset', 1, int), int)
|
||||||
reports = models.Report.not_reviewed(page)
|
reports = models.Report.not_reviewed(page)
|
||||||
|
report_action = forms.ReportActionForm(flask.request.form)
|
||||||
|
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST' and report_action.validate():
|
||||||
data = flask.request.form
|
action = report_action.action.data
|
||||||
torrent = models.Torrent.by_id(data['torrent'])
|
torrent_id = report_action.torrent.data
|
||||||
report = models.Report.by_id(data['report'])
|
report_id = report_action.report.data
|
||||||
|
torrent = models.Torrent.by_id(torrent_id)
|
||||||
|
report = models.Report.by_id(report_id)
|
||||||
|
|
||||||
if not torrent or not report or report.status != 0:
|
if not torrent or not report or report.status != 0:
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
else:
|
else:
|
||||||
if data['action'] == 'delete':
|
if action == 'delete':
|
||||||
torrent.deleted = True
|
torrent.deleted = True
|
||||||
report.status = 1
|
report.status = 1
|
||||||
elif data['action'] == 'hide':
|
elif action == 'hide':
|
||||||
torrent.hidden = True
|
torrent.hidden = True
|
||||||
report.status = 1
|
report.status = 1
|
||||||
else:
|
else:
|
||||||
report.status = 2
|
report.status = 2
|
||||||
|
|
||||||
models.Report.remove_reviewed(data['torrent'])
|
models.Report.remove_reviewed(torrent_id)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Closed report #{}'.format(report.id), 'success')
|
flask.flash('Closed report #{}'.format(report.id), 'success')
|
||||||
return flask.redirect(flask.url_for('view_reports'))
|
return flask.redirect(flask.url_for('view_reports'))
|
||||||
|
|
||||||
return flask.render_template('reports.html',
|
return flask.render_template('reports.html',
|
||||||
reports=reports)
|
reports=reports,
|
||||||
|
report_action=report_action)
|
||||||
|
|
||||||
|
|
||||||
def _get_cached_torrent_file(torrent):
|
def _get_cached_torrent_file(torrent):
|
||||||
|
|
|
@ -28,13 +28,10 @@
|
||||||
<td>{{ report.created_time }}</td>
|
<td>{{ report.created_time }}</td>
|
||||||
<td style="width: 15%">
|
<td style="width: 15%">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<select name="action" class="pull-left">
|
{{ report_action.csrf_token }}
|
||||||
<option value="close">Close</option>
|
{{ report_action.action }}
|
||||||
<option value="delete">Delete</option>
|
{{ report_action.torrent(value=report.torrent.id) }}
|
||||||
<option value="hide">Hide</option>
|
{{ report_action.report(value=report.id) }}
|
||||||
</select>
|
|
||||||
<input type="hidden" value="{{ report.torrent.id }}" name="torrent">
|
|
||||||
<input type="hidden" value="{{ report.id }}" name="report">
|
|
||||||
<button type="submit" class="btn btn-primary pull-right">Review</button>
|
<button type="submit" class="btn btn-primary pull-right">Review</button>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Reference in a new issue