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:
@@ -88,13 +88,13 @@ class BanForm(ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Ban
|
model = Ban
|
||||||
fields = ["ban_reason"]
|
fields = ["ban_reason", "board"]
|
||||||
|
|
||||||
def __init__(self, *args, op, **kwargs):
|
def __init__(self, *args, op, **kwargs):
|
||||||
super(BanForm, self).__init__(*args, **kwargs)
|
super(BanForm, self).__init__(*args, **kwargs)
|
||||||
self.op = op
|
self.op = op
|
||||||
self.instance.board = op.board
|
|
||||||
self.instance.ip = op.ip
|
self.instance.ip = op.ip
|
||||||
|
self.instance.post_id = op.id
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super(BanForm, self).clean()
|
super(BanForm, self).clean()
|
||||||
|
|||||||
@@ -260,10 +260,6 @@ def report_created(sender, instance, created, **kwargs):
|
|||||||
instance.record.save()
|
instance.record.save()
|
||||||
|
|
||||||
|
|
||||||
# class BanTemplate(models.Model):
|
|
||||||
# board =
|
|
||||||
|
|
||||||
|
|
||||||
class BanCommon(models.Model):
|
class BanCommon(models.Model):
|
||||||
# The reason for this ban
|
# The reason for this ban
|
||||||
ban_reason = models.TextField(blank=False)
|
ban_reason = models.TextField(blank=False)
|
||||||
@@ -275,6 +271,8 @@ class BanCommon(models.Model):
|
|||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
# Expiration date of this ban. If it is null, it is permanent.
|
# Expiration date of this ban. If it is null, it is permanent.
|
||||||
expires = models.DateTimeField(null=True, blank=True)
|
expires = models.DateTimeField(null=True, blank=True)
|
||||||
|
# The post ID that caused this ban
|
||||||
|
post_id = models.IntegerField(null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
@@ -320,10 +318,6 @@ class BanTemplate(models.Model):
|
|||||||
# The board that this template is for, or none.
|
# The board that this template is for, or none.
|
||||||
board = models.ForeignKey("Board", on_delete=models.CASCADE, null=True, blank=True)
|
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:
|
def __str__(self) -> str:
|
||||||
if self.board:
|
if self.board:
|
||||||
return f"/{self.board.url}/ - {self.name}"
|
return f"/{self.board.url}/ - {self.name}"
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
<th>{% translate 'Template' %}</th>
|
<th>{% translate 'Template' %}</th>
|
||||||
<td>
|
<td>
|
||||||
<select id="templates">
|
<select id="templates">
|
||||||
<option class="template_option" data-reason="" data-duration="">Custom</option>
|
<option class="template_option" data-board="" data-reason="" data-duration="">Custom</option>
|
||||||
{% for template in templates %}
|
{% for template in templates %}
|
||||||
<option class="template_option" data-reason="{{template.ban_reason}}" data-duration="{{template.duration}}">{{template.name}}</option>
|
<option class="template_option" data-board="{{template.board.id}}" data-reason="{{template.ban_reason}}" data-duration="{{template.duration}}">{{template.name}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
@@ -64,18 +64,23 @@ function templateSelect(e) {
|
|||||||
// uh oh, mixing django templates and JS
|
// uh oh, mixing django templates and JS
|
||||||
let banReason = $("#{{form.ban_reason.auto_id}}");
|
let banReason = $("#{{form.ban_reason.auto_id}}");
|
||||||
let duration = $("#{{form.duration.auto_id}}");
|
let duration = $("#{{form.duration.auto_id}}");
|
||||||
|
let board = $("#{{form.board.auto_id}}");
|
||||||
banReason.val(selected.attr("data-reason"));
|
banReason.val(selected.attr("data-reason"));
|
||||||
duration.val(selected.attr("data-duration"));
|
duration.val(selected.attr("data-duration"));
|
||||||
|
|
||||||
if(selected.val() === "Custom") {
|
if(parseInt(selected.attr("data-global"))) {
|
||||||
// unlock the controls
|
board.val("");
|
||||||
banReason.attr("readonly", false);
|
|
||||||
duration.attr("readonly", false);
|
|
||||||
} else {
|
} else {
|
||||||
// lock all controls
|
board.val(selected.attr("data-board"));
|
||||||
banReason.attr("readonly", true);
|
|
||||||
duration.attr("readonly", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let controls = [
|
||||||
|
banReason,
|
||||||
|
duration,
|
||||||
|
];
|
||||||
|
|
||||||
|
let readonly = (selected.val() !== "Custom");
|
||||||
|
controls.forEach(c => c.attr("readonly", readonly));
|
||||||
}
|
}
|
||||||
|
|
||||||
function templateSearch(e) {
|
function templateSearch(e) {
|
||||||
|
|||||||
@@ -54,6 +54,11 @@
|
|||||||
All boards
|
All boards
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
{% if ban.post_id %}
|
||||||
|
<p>
|
||||||
|
<strong>Post ID:</strong> {{ban.post_id}}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
<p>
|
<p>
|
||||||
<strong>Ban reason:</strong>
|
<strong>Ban reason:</strong>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user