Add admin capcodes
Sometimes, it is necessary for an admin or other moderator to reveal themselves. Capcodes allow them to do so by appending a special colored portion at the end of their name on a post. This adds object-level permissions, so if you have a moderator who shouldn't be able to use the "admin" capcode, you can give them permission only to the "moderator" capcode. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -2,17 +2,21 @@ from datetime import timedelta
|
||||
import os
|
||||
from pathlib import Path
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.base import ContentFile
|
||||
from django.db import models
|
||||
from django.db.models import signals
|
||||
from django.db.models.deletion import SET_NULL
|
||||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
from colorfield.fields import ColorField
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def image_upload(instance, filename):
|
||||
op_id = instance.op.id if instance.op else instance.id
|
||||
@@ -36,6 +40,9 @@ def thumbs_upload(instance, filename):
|
||||
return f"{instance.board.url}/{now_sec}t{ext}"
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class Board(models.Model):
|
||||
# The short URL name for the board
|
||||
url = models.CharField(max_length=255, null=False, blank=False, unique=True)
|
||||
@@ -84,6 +91,8 @@ class Post(models.Model):
|
||||
text = models.TextField(max_length=10000, null=False, blank=True)
|
||||
# The IP address of the user that made this post
|
||||
ip = models.GenericIPAddressField()
|
||||
# Capcode
|
||||
capcode = models.ForeignKey("Capcode", null=True, blank=True, on_delete=SET_NULL)
|
||||
# Creation time
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
# Last bump time
|
||||
@@ -334,7 +343,12 @@ class BanTemplate(models.Model):
|
||||
|
||||
|
||||
class Capcode(models.Model):
|
||||
# Content to display *before* the capcoded user's name.
|
||||
prefix = models.CharField(max_length=100)
|
||||
# Content to display *after* the capcoded user's name.
|
||||
suffix = models.CharField(max_length=100)
|
||||
color = ColorField()
|
||||
|
||||
class Meta:
|
||||
permissions = (("use_capcode", "Can use capcode"),)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.suffix
|
||||
|
||||
Reference in New Issue
Block a user