Add board selection to ban creation and post ID to ban model

* Board selection is allowed for when you want to make a global ban
* Post ID is added to ban model for referencing later

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-06-23 18:57:23 -07:00
parent b64559aba9
commit a5510d9552
4 changed files with 23 additions and 19 deletions

View File

@@ -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}"