Content warning name customisation
Allows the name of Content Warning to be customized (e.g. to "Content Summary"). Fixes #28.
This commit is contained in:
parent
db0edcd2ae
commit
cdfff32f9a
|
@ -4,6 +4,7 @@
|
|||
*.pyc
|
||||
*.sqlite3
|
||||
.venv
|
||||
.vscode
|
||||
/*.env
|
||||
/build
|
||||
/docs/_build
|
||||
|
|
|
@ -135,9 +135,10 @@ class Compose(FormView):
|
|||
)
|
||||
content_warning = forms.CharField(
|
||||
required=False,
|
||||
label=Config.lazy_system_value("content_warning_text"),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": "Content Warning",
|
||||
"placeholder": Config.lazy_system_value("content_warning_text"),
|
||||
},
|
||||
),
|
||||
help_text="Optional - Post will be hidden behind this text until clicked",
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.utils.decorators import method_decorator
|
|||
from django.views.generic import FormView, ListView
|
||||
|
||||
from activities.models import Post, PostInteraction, TimelineEvent
|
||||
from core.models import Config
|
||||
from users.decorators import identity_required
|
||||
|
||||
|
||||
|
@ -23,10 +24,11 @@ class Home(FormView):
|
|||
)
|
||||
content_warning = forms.CharField(
|
||||
required=False,
|
||||
label=Config.lazy_system_value("content_warning_text"),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": "Content Warning",
|
||||
"class": "hidden",
|
||||
"placeholder": Config.lazy_system_value("content_warning_text"),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
|
|
@ -5,6 +5,7 @@ import pydantic
|
|||
from django.core.files import File
|
||||
from django.db import models
|
||||
from django.templatetags.static import static
|
||||
from django.utils.functional import lazy
|
||||
|
||||
from core.uploads import upload_namer
|
||||
from takahe import __version__
|
||||
|
@ -55,6 +56,15 @@ class Config(models.Model):
|
|||
|
||||
system: ClassVar["Config.ConfigOptions"] # type: ignore
|
||||
|
||||
@classmethod
|
||||
def lazy_system_value(cls, key: str):
|
||||
"""
|
||||
Lazily load a System.Config value
|
||||
"""
|
||||
if key not in cls.SystemOptions.__fields__:
|
||||
raise KeyError(f"Undefined SystemOption for {key}")
|
||||
return lazy(lambda: getattr(Config.system, key))
|
||||
|
||||
@classmethod
|
||||
def load_values(cls, options_class, filters):
|
||||
"""
|
||||
|
@ -166,6 +176,7 @@ class Config(models.Model):
|
|||
signup_allowed: bool = True
|
||||
signup_invite_only: bool = False
|
||||
signup_text: str = ""
|
||||
content_warning_text: str = "Content Warning"
|
||||
|
||||
post_length: int = 500
|
||||
identity_min_length: int = 2
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import re
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from activities.views.posts import Compose
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_content_warning_text(identity, user, rf, config_system):
|
||||
request = rf.get("/compose/")
|
||||
request.user = user
|
||||
request.identity = identity
|
||||
|
||||
config_system.content_warning_text = "Content Summary"
|
||||
with mock.patch("core.models.Config.load_system", return_value=config_system):
|
||||
view = Compose.as_view()
|
||||
resp = view(request)
|
||||
assert resp.status_code == 200
|
||||
content = str(resp.rendered_content)
|
||||
assert 'placeholder="Content Summary"' in content
|
||||
assert re.search(
|
||||
r"<label.*>\s*Content Summary\s*</label>", content, flags=re.MULTILINE
|
||||
)
|
|
@ -0,0 +1,18 @@
|
|||
import mock
|
||||
import pytest
|
||||
|
||||
from activities.views.timelines import Home
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_content_warning_text(identity, user, rf, config_system):
|
||||
request = rf.get("/")
|
||||
request.user = user
|
||||
request.identity = identity
|
||||
|
||||
config_system.content_warning_text = "Content Summary"
|
||||
with mock.patch("core.models.Config.load_system", return_value=config_system):
|
||||
view = Home.as_view()
|
||||
resp = view(request)
|
||||
assert resp.status_code == 200
|
||||
assert 'placeholder="Content Summary"' in str(resp.rendered_content)
|
|
@ -62,11 +62,16 @@ def config_system(keypair):
|
|||
|
||||
@pytest.fixture
|
||||
@pytest.mark.django_db
|
||||
def identity():
|
||||
def user() -> User:
|
||||
return User.objects.create(email="test@example.com")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.mark.django_db
|
||||
def identity(user):
|
||||
"""
|
||||
Creates a basic test identity with a user and domain.
|
||||
"""
|
||||
user = User.objects.create(email="test@example.com")
|
||||
domain = Domain.objects.create(domain="example.com", local=True, public=True)
|
||||
identity = Identity.objects.create(
|
||||
actor_uri="https://example.com/test-actor/",
|
||||
|
|
|
@ -37,6 +37,10 @@ class BasicSettings(AdminSettingsPage):
|
|||
"title": "Maximum Post Length",
|
||||
"help_text": "The maximum number of characters allowed per post",
|
||||
},
|
||||
"content_warning_text": {
|
||||
"title": "Content Warning Feature Name",
|
||||
"help_text": "What the feature that lets users provide post summaries is called",
|
||||
},
|
||||
"site_about": {
|
||||
"title": "About This Site",
|
||||
"help_text": "Displayed on the homepage and the about page.\nNewlines are preserved; HTML also allowed.",
|
||||
|
@ -87,7 +91,7 @@ class BasicSettings(AdminSettingsPage):
|
|||
"highlight_color",
|
||||
],
|
||||
"Signups": ["signup_allowed", "signup_invite_only", "signup_text"],
|
||||
"Posts": ["post_length"],
|
||||
"Posts": ["post_length", "content_warning_text"],
|
||||
"Identities": [
|
||||
"identity_max_per_user",
|
||||
"identity_min_length",
|
||||
|
|
Loading…
Reference in New Issue