Fix Comments admin 500 on snippet index #38

Merged
mark merged 1 commits from fix/comments-admin-500-issue-37 into main 2026-03-03 13:31:40 +00:00
2 changed files with 24 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import pytest
from django.test import override_settings
from apps.blog.models import ArticleIndexPage, ArticlePage
from apps.blog.tests.factories import AuthorFactory
@@ -79,3 +80,18 @@ def test_bulk_approve_action_marks_selected_pending_comments_as_approved(home_pa
assert child_updates == 0
assert pending.is_approved is True
assert approved.is_approved is True
@pytest.mark.django_db
@override_settings(ALLOWED_HOSTS=["testserver", "localhost", "127.0.0.1"])
def test_comments_snippet_index_page_loads(client, django_user_model, home_page):
admin = django_user_model.objects.create_superuser(
username="admin",
email="admin@example.com",
password="admin-pass",
)
client.force_login(admin)
response = client.get("/cms/snippets/comments/comment/")
assert response.status_code == 200

View File

@@ -4,7 +4,7 @@ from django.db.models import Count, Q
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext
from wagtail import hooks
from wagtail.admin.ui.tables import BooleanColumn
from wagtail.admin.ui.tables import BooleanColumn, Column
from wagtail.snippets.bulk_actions.snippet_bulk_action import SnippetBulkAction
from wagtail.snippets.models import register_snippet
from wagtail.snippets.permissions import get_permission_name
@@ -45,7 +45,13 @@ class CommentViewSet(SnippetViewSet):
model = Comment
queryset = Comment.objects.all()
icon = "comment"
list_display = ["author_name", "article", BooleanColumn("is_approved"), "pending_in_article", "created_at"]
list_display = [
"author_name",
"article",
BooleanColumn("is_approved"),
Column("pending_in_article", label="Pending (article)"),
"created_at",
]
list_filter = ["is_approved"]
search_fields = ["author_name", "body"]
add_to_admin_menu = True
@@ -62,11 +68,5 @@ class CommentViewSet(SnippetViewSet):
)
)
def pending_in_article(self, obj):
return obj.pending_in_article
pending_in_article.short_description = "Pending (article)" # type: ignore[attr-defined]
register_snippet(CommentViewSet)
hooks.register("register_bulk_action", ApproveCommentBulkAction)