Add ability to create bans from reports
This is done in the admin view and opens a new iframed window. The ban form is pretty barebones and doesn't have full functionality yet, but that is coming. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django import forms
|
||||
from django.forms import ModelForm, ModelChoiceField
|
||||
from board.models import Post, Report, ReportReason, ReportRecord
|
||||
from django.utils import timezone
|
||||
from board.models import Ban, Post, Report, ReportReason, ReportRecord
|
||||
from hcaptcha.fields import hCaptchaField
|
||||
|
||||
|
||||
@@ -74,3 +76,32 @@ class ReportForm(ModelForm):
|
||||
record = ReportRecord.objects.create(post=self.op)
|
||||
self.instance.record = record
|
||||
return super(ReportForm, self).clean()
|
||||
|
||||
|
||||
class BanForm(ModelForm):
|
||||
"""
|
||||
A form used to create bans based on specific posts.
|
||||
"""
|
||||
|
||||
# uses ban_form.html
|
||||
duration = forms.IntegerField(label="Duration (days)", min_value=1, required=False)
|
||||
|
||||
class Meta:
|
||||
model = Ban
|
||||
fields = ["ban_reason"]
|
||||
|
||||
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
|
||||
|
||||
def clean(self):
|
||||
super(BanForm, self).clean()
|
||||
now = timezone.now()
|
||||
duration = self.cleaned_data["duration"]
|
||||
if duration:
|
||||
expires = now + timezone.timedelta(days=duration)
|
||||
else:
|
||||
expires = None
|
||||
self.instance.expires = expires
|
||||
|
||||
Reference in New Issue
Block a user