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:
|
||||
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()
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
<th>{% translate 'Template' %}</th>
|
||||
<td>
|
||||
<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 %}
|
||||
<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 %}
|
||||
</select>
|
||||
</td>
|
||||
@@ -64,18 +64,23 @@ function templateSelect(e) {
|
||||
// uh oh, mixing django templates and JS
|
||||
let banReason = $("#{{form.ban_reason.auto_id}}");
|
||||
let duration = $("#{{form.duration.auto_id}}");
|
||||
let board = $("#{{form.board.auto_id}}");
|
||||
banReason.val(selected.attr("data-reason"));
|
||||
duration.val(selected.attr("data-duration"));
|
||||
|
||||
if(selected.val() === "Custom") {
|
||||
// unlock the controls
|
||||
banReason.attr("readonly", false);
|
||||
duration.attr("readonly", false);
|
||||
if(parseInt(selected.attr("data-global"))) {
|
||||
board.val("");
|
||||
} else {
|
||||
// lock all controls
|
||||
banReason.attr("readonly", true);
|
||||
duration.attr("readonly", true);
|
||||
board.val(selected.attr("data-board"));
|
||||
}
|
||||
|
||||
let controls = [
|
||||
banReason,
|
||||
duration,
|
||||
];
|
||||
|
||||
let readonly = (selected.val() !== "Custom");
|
||||
controls.forEach(c => c.attr("readonly", readonly));
|
||||
}
|
||||
|
||||
function templateSearch(e) {
|
||||
|
||||
@@ -54,6 +54,11 @@
|
||||
All boards
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if ban.post_id %}
|
||||
<p>
|
||||
<strong>Post ID:</strong> {{ban.post_id}}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<strong>Ban reason:</strong>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user