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:
@@ -1,5 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from board.models import Board, Post
|
from board.models import Board, Post, ReportReason, Report
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Board)
|
@admin.register(Board)
|
||||||
@@ -10,3 +10,13 @@ class BoardAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(Post)
|
@admin.register(Post)
|
||||||
class PostAdmin(admin.ModelAdmin):
|
class PostAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(ReportReason)
|
||||||
|
class ReportReasonAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Report)
|
||||||
|
class ReportAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ class Board(models.Model):
|
|||||||
for thread in to_remove:
|
for thread in to_remove:
|
||||||
thread.delete()
|
thread.delete()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"/{self.url}/ - {self.name}"
|
||||||
|
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
# Board that this post was made on
|
# Board that this post was made on
|
||||||
@@ -198,3 +201,52 @@ def post_deleted(sender, instance, **kwargs):
|
|||||||
os.remove(instance.image.path)
|
os.remove(instance.image.path)
|
||||||
if instance.thumbnail and Path(instance.thumbnail.path).is_file():
|
if instance.thumbnail and Path(instance.thumbnail.path).is_file():
|
||||||
os.remove(instance.thumbnail.path)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user