diff --git a/board/forms.py b/board/forms.py index 12cdedb..df239e5 100644 --- a/board/forms.py +++ b/board/forms.py @@ -6,6 +6,7 @@ from django import forms from django.forms import ModelForm, ModelChoiceField from django.forms.models import fields_for_model from django.utils import timezone +from django.utils.translation import gettext as _ from guardian.shortcuts import get_objects_for_user from board.models import Ban, Post, Report, ReportReason, ReportRecord from hcaptcha.fields import hCaptchaField @@ -38,7 +39,7 @@ class PostForm(ModelForm): capcode = self.cleaned_data["capcode"] if capcode: if not self.user or not self.user.has_perm("board.use_capcode", capcode): - raise ValidationError("Could not create post") + raise ValidationError(_("Could not create post")) class ReplyForm(PostForm): @@ -67,10 +68,12 @@ class ReplyForm(PostForm): def clean(self): super().clean() + if self.instance.op.lock: + raise ValidationError(_("This thread is locked, you cannot reply to it")) capcode = self.cleaned_data["capcode"] if capcode: if not self.user or not self.user.has_perm("board.use_capcode", capcode): - raise ValidationError("Could not create post") + raise ValidationError(_("Could not create post")) class ReportForm(ModelForm): @@ -142,7 +145,7 @@ class PostModifyForm(ModelForm): model = Post # we specify fields up here too because otherwise they won't be # recognized by the form to update values - fields = ["sticky", "bump"] + fields = ["sticky", "bump", "lock"] def __init__(self, *args, user, **kwargs): super(PostModifyForm, self).__init__(*args, **kwargs) @@ -152,6 +155,8 @@ class PostModifyForm(ModelForm): fields += ["sticky"] if self.user.has_perm("board.set_bump"): fields += ["bump"] + if self.user.has_perm("board.set_lock") and not self.instance.op: + fields += ["lock"] # NOTE: # We do *not* need to check permissions against these fields we're # setting down here in the self.clean() function in the case that a diff --git a/board/models.py b/board/models.py index 74f00ba..12c4c30 100644 --- a/board/models.py +++ b/board/models.py @@ -93,8 +93,10 @@ class Post(models.Model): ip = models.GenericIPAddressField() # Capcode capcode = models.ForeignKey("Capcode", null=True, blank=True, on_delete=SET_NULL) - # Post is stickied + # Post is stickied - it remains at the top of the bump list. sticky = models.BooleanField(default=False, blank=True) + # Post is locked - nobody can post in it. + lock = models.BooleanField(default=False, blank=True) # Creation time created = models.DateTimeField(auto_now_add=True) # Last bump time @@ -122,6 +124,7 @@ class Post(models.Model): permissions = [ ("set_sticky", "Can sticky post"), ("set_bump", "Can bumplock post"), + ("set_lock", "Can lock post"), ] def save(self, *args, **kwargs): diff --git a/board/templates/board/post_snippet.html b/board/templates/board/post_snippet.html index 2583eca..85ad8c1 100644 --- a/board/templates/board/post_snippet.html +++ b/board/templates/board/post_snippet.html @@ -27,9 +27,12 @@ {% endif %} -{# Post ID, sticky, username, time #} +{# Post ID, status icons, username, time #} {% if post.sticky and not post.op %} - + +{% endif %} +{% if post.lock and not post.op %} + {% endif %} #. {{post.id}} diff --git a/board/templates/board/reply_create_view.html b/board/templates/board/reply_create_view.html index bef694a..8bebc2a 100644 --- a/board/templates/board/reply_create_view.html +++ b/board/templates/board/reply_create_view.html @@ -28,17 +28,32 @@ input[type=text] { {% block content %}
{% csrf_token %} + {% if form.errors %} + {{form.non_field_errors}} + {% endif %} {% for field in form %} {% if field.name != "capcode" %} - - - - + {% if field.errors %} + + + + + {% endif %} + + + + {% endif %} {% endfor %} {% if capcodes %} + {% if form.capcode.errors %} + + + + + {% endif %}
{{field.label_tag}}{{field}}
{{field.errors}}
{{field.label_tag}}{{field}}
{{form.capcode.errors}}
{{form.capcode.label_tag}} {{form.capcode}}