Fix admin message auto-dismiss and Category plural label
Admin messages now auto-clear after 8 seconds via the w-messages Stimulus controller's autoClear value, preventing message pile-up. Category model gains verbose_name_plural so Wagtail shows "Categories" instead of "Categorys" in the snippets menu. Closes #62 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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'},
|
||||
),
|
||||
]
|
||||
@@ -168,6 +168,7 @@ class Category(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ["sort_order", "name"]
|
||||
verbose_name_plural = "categories"
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -386,6 +386,31 @@ def test_article_save_autogenerates_summary_when_missing(article_index):
|
||||
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
|
||||
def test_article_page_omits_admin_messages_on_frontend(article_page, rf):
|
||||
"""Frontend templates should not render admin session messages."""
|
||||
|
||||
@@ -76,3 +76,21 @@ def test_wagtail_admin_template_deduplicates_consecutive_messages(client, django
|
||||
assert response.status_code == 200
|
||||
assert content.count("has been updated.") == 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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{% keyboard_shortcuts_dialog %}
|
||||
<main class="content-wrapper w-overflow-x-hidden" id="main">
|
||||
<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">
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
|
||||
Reference in New Issue
Block a user