mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-11-14 06:39:16 +00:00
parent
80c9d580eb
commit
532439356f
|
@ -346,6 +346,7 @@ class BanForm(FlaskForm):
|
|||
|
||||
class NukeForm(FlaskForm):
|
||||
nuke_torrents = SubmitField("\U0001F4A3 Nuke Torrents")
|
||||
nuke_comments = SubmitField("\U0001F4A3 Nuke Comments")
|
||||
|
||||
|
||||
class UploadForm(FlaskForm):
|
||||
|
|
|
@ -199,9 +199,15 @@ class TorrentBase(DeclarativeHelperBase):
|
|||
return '<{0} #{1.id} \'{1.display_name}\' {1.filesize}b>'.format(type(self).__name__, self)
|
||||
|
||||
def update_comment_count(self):
|
||||
self.comment_count = Comment.query.filter_by(torrent_id=self.id).count()
|
||||
self.comment_count = db.session.query(func.count(
|
||||
Comment.id)).filter_by(torrent_id=self.id).first()[0]
|
||||
return self.comment_count
|
||||
|
||||
@classmethod
|
||||
def update_comment_count_db(cls, torrent_id):
|
||||
cls.query.filter_by(id=torrent_id).update({'comment_count': db.session.query(
|
||||
func.count(Comment.id)).filter_by(torrent_id=torrent_id).as_scalar()}, False)
|
||||
|
||||
@property
|
||||
def created_utc_timestamp(self):
|
||||
''' Returns a UTC POSIX timestamp, as seconds '''
|
||||
|
|
|
@ -29,7 +29,7 @@ def create_magnet_from_es_torrent():
|
|||
flask_url_for = flask.url_for
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=1024*4)
|
||||
@functools.lru_cache(maxsize=1024 * 4)
|
||||
def _caching_url_for(endpoint, **values):
|
||||
return flask_url_for(endpoint, **values)
|
||||
|
||||
|
|
|
@ -138,6 +138,9 @@
|
|||
<div class="col-md-6 text-left">
|
||||
{{ nuke_form.nuke_torrents(class="btn btn-danger", formaction=url_for('users.nuke_user_torrents', user_name=user.username)) }}
|
||||
</div>
|
||||
<div class="col-md-6 text-right">
|
||||
{{ nuke_form.nuke_comments(class="btn btn-danger", formaction=url_for('users.nuke_user_comments', user_name=user.username)) }}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
|
|
@ -301,6 +301,50 @@ def nuke_user_torrents(user_name):
|
|||
return flask.redirect(url)
|
||||
|
||||
|
||||
@bp.route('/user/<user_name>/nuke/comments', methods=['POST'])
|
||||
@admin_only
|
||||
def nuke_user_comments(user_name):
|
||||
user = models.User.by_username(user_name)
|
||||
if not user:
|
||||
flask.abort(404)
|
||||
|
||||
nuke_form = forms.NukeForm(flask.request.form)
|
||||
if not nuke_form.validate():
|
||||
flask.abort(401)
|
||||
url = flask.url_for('users.view_user', user_name=user.username)
|
||||
nyaa_deleted = 0
|
||||
sukebei_deleted = 0
|
||||
nyaa_torrents = set()
|
||||
sukebei_torrents = set()
|
||||
for c in chain(user.nyaa_comments, user.sukebei_comments):
|
||||
nyaa_torrents.add(c.torrent_id)
|
||||
sukebei_torrents.add(c.torrent_id)
|
||||
db.session.delete(c)
|
||||
if isinstance(c, models.NyaaComment):
|
||||
nyaa_deleted += 1
|
||||
else:
|
||||
sukebei_deleted += 1
|
||||
|
||||
for tid in nyaa_torrents:
|
||||
models.NyaaTorrent.update_comment_count_db(tid)
|
||||
for tid in sukebei_torrents:
|
||||
models.SukebeiTorrent.update_comment_count_db(tid)
|
||||
|
||||
for log_flavour, num in ((models.NyaaAdminLog, nyaa_deleted),
|
||||
(models.SukebeiAdminLog, sukebei_deleted)):
|
||||
if num > 0:
|
||||
log = "Nuked {0} comments of [{1}]({2})".format(num,
|
||||
user.username,
|
||||
url)
|
||||
adminlog = log_flavour(log=log, admin_id=flask.g.user.id)
|
||||
db.session.add(adminlog)
|
||||
|
||||
db.session.commit()
|
||||
flask.flash('Comments of {0} have been nuked.'.format(user.username),
|
||||
'success')
|
||||
return flask.redirect(url)
|
||||
|
||||
|
||||
def _create_user_class_choices(user):
|
||||
choices = [('regular', 'Regular')]
|
||||
default = 'regular'
|
||||
|
|
Loading…
Reference in a new issue