diff --git a/board/admin.py b/board/admin.py index abf7c31..66725c8 100644 --- a/board/admin.py +++ b/board/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from board.models import Board, Post +from board.models import Board, Post, ReportReason, Report @admin.register(Board) @@ -10,3 +10,13 @@ class BoardAdmin(admin.ModelAdmin): @admin.register(Post) class PostAdmin(admin.ModelAdmin): pass + + +@admin.register(ReportReason) +class ReportReasonAdmin(admin.ModelAdmin): + pass + + +@admin.register(Report) +class ReportAdmin(admin.ModelAdmin): + pass diff --git a/board/models.py b/board/models.py index ae196b0..5e2565d 100644 --- a/board/models.py +++ b/board/models.py @@ -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)