Add reports, report reasons, bans, and ban templates

Reports are created by users.

Bans are created by moderators, in response to reports.

Report reasons and ban templates are created by admins, which give a
template for reports sent and bans issued.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-05-07 17:35:47 -07:00
parent 1aa263fd7d
commit 2940affae3
2 changed files with 63 additions and 1 deletions

View File

@@ -65,6 +65,9 @@ class Board(models.Model):
for thread in to_remove:
thread.delete()
def __str__(self):
return f"/{self.url}/ - {self.name}"
class Post(models.Model):
# Board that this post was made on
@@ -198,3 +201,52 @@ def post_deleted(sender, instance, **kwargs):
os.remove(instance.image.path)
if instance.thumbnail and Path(instance.thumbnail.path).is_file():
os.remove(instance.thumbnail.path)
class ReportReason(models.Model):
# The reason for this report.
reason = models.CharField(max_length=255)
# The weight of this report reason.
# Heigher = more urgent.
weight = models.IntegerField(default=1)
# Urgency. If true, this post is probably reported as illegal content.
urgent = models.BooleanField(default=False)
# This is a board-specific report reason
board = models.ForeignKey("Board", on_delete=models.CASCADE, null=True)
def __str__(self):
return self.reason
class Report(models.Model):
# Post that this report is for
post = models.ForeignKey("Post", on_delete=models.CASCADE)
# Reason for this report
reason = models.ForeignKey("ReportReason", on_delete=models.SET_NULL, null=True)
# IP address of the reporter
ip = models.GenericIPAddressField()
class Ban(models.Model):
# IP address of the reporter
ip = models.GenericIPAddressField()
# The reason for this ban
ban_reason = models.TextField(blank=False)
# Board that this ban is for. If null, then all boards.
# Even though this is nullable, we just want to delete all reports for a
# board if that board is deleted.
board = models.ForeignKey("Board", on_delete=models.CASCADE, null=True)
# The time that this ban was created.
created = models.DateTimeField(auto_now_add=True)
# Expiration date of this ban.
expires = models.DateTimeField(auto_now_add=True)
class BanTemplate(models.Model):
# The reason for this ban
ban_reason = models.TextField(blank=False)
# The duration of the ban
duration = models.DurationField()
def create_ban(self, ip: str) -> Ban:
return Ban.objects.create(ip=ip, ban_reason=self.ban_reason)