Fix admin message auto-dismiss and Category plural label #64

Merged
claude merged 1 commits from fix/issue-62-messages-and-categories into main 2026-03-19 00:15:51 +00:00
5 changed files with 62 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.2.12 on 2026-03-19 00:10
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('blog', '0004_backfill_published_date'),
]
operations = [
migrations.AlterModelOptions(
name='category',
options={'ordering': ['sort_order', 'name'], 'verbose_name_plural': 'categories'},
),
]

View File

@@ -168,6 +168,7 @@ class Category(models.Model):
class Meta: class Meta:
ordering = ["sort_order", "name"] ordering = ["sort_order", "name"]
verbose_name_plural = "categories"
def __str__(self): def __str__(self):
return self.name return self.name

View File

@@ -386,6 +386,31 @@ def test_article_save_autogenerates_summary_when_missing(article_index):
assert article.summary == "This should become the summary text." assert article.summary == "This should become the summary text."
@pytest.mark.django_db
def test_category_verbose_name_plural():
"""Category Meta should define verbose_name_plural as 'categories'."""
assert Category._meta.verbose_name_plural == "categories"
@pytest.mark.django_db
@override_settings(ALLOWED_HOSTS=["testserver", "localhost", "127.0.0.1"])
def test_snippet_category_listing_shows_categories(client, django_user_model):
"""Categories created in the database should appear in the Snippets listing."""
Category.objects.create(name="Reviews", slug="reviews")
Category.objects.create(name="Tutorials", slug="tutorials")
admin = django_user_model.objects.create_superuser(
username="admin-cat", email="admin-cat@example.com", password="admin-pass"
)
client.force_login(admin)
response = client.get("/cms/snippets/blog/category/")
content = response.content.decode()
assert response.status_code == 200
assert "Reviews" in content
assert "Tutorials" in content
@pytest.mark.django_db @pytest.mark.django_db
def test_article_page_omits_admin_messages_on_frontend(article_page, rf): def test_article_page_omits_admin_messages_on_frontend(article_page, rf):
"""Frontend templates should not render admin session messages.""" """Frontend templates should not render admin session messages."""

View File

@@ -76,3 +76,21 @@ def test_wagtail_admin_template_deduplicates_consecutive_messages(client, django
assert response.status_code == 200 assert response.status_code == 200
assert content.count("has been updated.") == 1 assert content.count("has been updated.") == 1
assert content.count("has been published.") == 1 assert content.count("has been published.") == 1
@pytest.mark.django_db
@override_settings(ROOT_URLCONF="apps.core.tests.test_message_handling")
def test_admin_messages_have_auto_clear(client, django_user_model):
"""The messages container must set auto-clear so messages dismiss themselves."""
admin = django_user_model.objects.create_superuser(
username="admin-autoclear",
email="admin-autoclear@example.com",
password="admin-pass",
)
client.force_login(admin)
response = client.get("/cms/__tests__/admin-messages/")
content = response.content.decode()
assert response.status_code == 200
assert "data-w-messages-auto-clear-value" in content

View File

@@ -8,7 +8,7 @@
{% keyboard_shortcuts_dialog %} {% keyboard_shortcuts_dialog %}
<main class="content-wrapper w-overflow-x-hidden" id="main"> <main class="content-wrapper w-overflow-x-hidden" id="main">
<div class="content"> <div class="content">
<div class="messages" role="status" data-controller="w-messages" data-action="w-messages:add@document->w-messages#add" data-w-messages-added-class="new" data-w-messages-show-class="appear" data-w-messages-show-delay-value="100"> <div class="messages" role="status" data-controller="w-messages" data-action="w-messages:add@document->w-messages#add" data-w-messages-added-class="new" data-w-messages-show-class="appear" data-w-messages-show-delay-value="100" data-w-messages-auto-clear-value="8000">
<ul data-w-messages-target="container"> <ul data-w-messages-target="container">
{% if messages %} {% if messages %}
{% for message in messages %} {% for message in messages %}