diff --git a/board/forms.py b/board/forms.py index 2f8d039..a7e86f5 100644 --- a/board/forms.py +++ b/board/forms.py @@ -88,13 +88,13 @@ class BanForm(ModelForm): class Meta: model = Ban - fields = ["ban_reason"] + fields = ["ban_reason", "board"] def __init__(self, *args, op, **kwargs): super(BanForm, self).__init__(*args, **kwargs) self.op = op - self.instance.board = op.board self.instance.ip = op.ip + self.instance.post_id = op.id def clean(self): super(BanForm, self).clean() diff --git a/board/models.py b/board/models.py index 1b53df8..ec8c492 100644 --- a/board/models.py +++ b/board/models.py @@ -260,10 +260,6 @@ def report_created(sender, instance, created, **kwargs): instance.record.save() -# class BanTemplate(models.Model): -# board = - - class BanCommon(models.Model): # The reason for this ban ban_reason = models.TextField(blank=False) @@ -275,6 +271,8 @@ class BanCommon(models.Model): created = models.DateTimeField(auto_now_add=True) # Expiration date of this ban. If it is null, it is permanent. expires = models.DateTimeField(null=True, blank=True) + # The post ID that caused this ban + post_id = models.IntegerField(null=True, blank=True) class Meta: abstract = True @@ -320,10 +318,6 @@ class BanTemplate(models.Model): # The board that this template is for, or none. board = models.ForeignKey("Board", on_delete=models.CASCADE, null=True, blank=True) - def create_ban(self, ip: str) -> Ban: - expires = timezone.now() + self.duration - return Ban.objects.create(ip=ip, ban_reason=self.ban_reason, expires=expires) - def __str__(self) -> str: if self.board: return f"/{self.board.url}/ - {self.name}" diff --git a/board/templates/board/ban_form.html b/board/templates/board/ban_form.html index 0d89013..ac723af 100644 --- a/board/templates/board/ban_form.html +++ b/board/templates/board/ban_form.html @@ -25,9 +25,9 @@
+ Post ID: {{ban.post_id}} +
+ {% endif %}Ban reason: