From 1e61522f7ae30d982d3342b2a2a98c125d8c21c8 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 23 Jun 2022 21:49:04 -0700 Subject: [PATCH] Delete posts after a ban is created for them After a user is banned for a post, that post now gets deleted. There's no way to turn this off yet. Signed-off-by: Alek Ratzloff --- board/models.py | 8 ++++++++ board/templates/admin/board/reportrecord/change_list.html | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/board/models.py b/board/models.py index ec8c492..9c0be28 100644 --- a/board/models.py +++ b/board/models.py @@ -308,6 +308,14 @@ class Ban(BanCommon): return f"Ban for {self.ip}" +@receiver(signals.post_save, sender=Ban) +def ban_created(sender, instance, created, **kwargs): + if created: + if instance.post_id: + post = Post.objects.get(id=instance.post_id) + post.delete() + + class BanTemplate(models.Model): # The name of this template name = models.CharField(max_length=100) diff --git a/board/templates/admin/board/reportrecord/change_list.html b/board/templates/admin/board/reportrecord/change_list.html index 10ca523..1eec199 100644 --- a/board/templates/admin/board/reportrecord/change_list.html +++ b/board/templates/admin/board/reportrecord/change_list.html @@ -51,6 +51,7 @@ function openBanWindow(e) { root: document.body, onclose: function(force) { window.top.banWindow = null; + window.top.location.reload(); } }); } @@ -61,6 +62,5 @@ function onLoad(e) { $(".ban_link").on("click", openBanWindow); $(window).on("load", onLoad); - {% endblock %} \ No newline at end of file