From b4df8b9756cd01c1009672c7fa72214c2fcf6fc4 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 19 Jun 2022 22:41:02 -0700 Subject: [PATCH] Fix report form to use appropriate templates Signed-off-by: Alek Ratzloff --- board/forms.py | 7 +++++-- board/models.py | 26 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/board/forms.py b/board/forms.py index 0a0b7b3..faf2c2d 100644 --- a/board/forms.py +++ b/board/forms.py @@ -1,7 +1,8 @@ from django.conf import settings from django.db import transaction -from django.forms import ModelForm -from board.models import Post, Report, ReportRecord +from django.db.models import Q +from django.forms import ModelForm, ModelChoiceField +from board.models import Post, Report, ReportReason, ReportRecord from hcaptcha.fields import hCaptchaField @@ -61,6 +62,8 @@ class ReportForm(ModelForm): super(ReportForm, self).__init__(*args, **kwargs) self.instance.ip = ip self.op = op + queryset = ReportReason.objects.filter(Q(board=None) | Q(board=board)) + self.fields["reason"] = ModelChoiceField(queryset=queryset) def clean(self): # Get or create the record before creating the model diff --git a/board/models.py b/board/models.py index f6cf1fb..1666895 100644 --- a/board/models.py +++ b/board/models.py @@ -226,9 +226,6 @@ class ReportRecord(models.Model): # If this report is urgent or not urgent = models.BooleanField(default=False) - # def urgent(self) -> bool: - # return self.report_set().aggregate( - class Report(models.Model): """ @@ -263,8 +260,25 @@ def report_created(sender, instance, created, **kwargs): instance.record.save() +# class BanTemplate(models.Model): +# board = + + +class RangeBan(models.Model): + # Starting IP address of the ban + start = models.GenericIPAddressField() + # Ending IP address of the ban + end = models.GenericIPAddressField() + # The reason for this ban + ban_reason = models.TextField(blank=False) + # The time that this ban was created. + created = models.DateTimeField(auto_now_add=True) + # Expiration date of this ban. If it is null, it is permanent. + expires = models.DateTimeField(null=True) + + class Ban(models.Model): - # IP address of the reporter + # IP address of the ban ip = models.GenericIPAddressField() # The reason for this ban ban_reason = models.TextField(blank=False) @@ -274,8 +288,8 @@ class Ban(models.Model): 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() + # Expiration date of this ban. If it is null, it is permanent. + expires = models.DateTimeField(null=True) class BanTemplate(models.Model):