Fix comments snippet admin 500
Use an explicit Wagtail Column for pending_in_article in CommentViewSet list_display and add a regression test for /cms/snippets/comments/comment/. Fixes #37 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
from django.test import override_settings
|
||||||
|
|
||||||
from apps.blog.models import ArticleIndexPage, ArticlePage
|
from apps.blog.models import ArticleIndexPage, ArticlePage
|
||||||
from apps.blog.tests.factories import AuthorFactory
|
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 child_updates == 0
|
||||||
assert pending.is_approved is True
|
assert pending.is_approved is True
|
||||||
assert approved.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
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from django.db.models import Count, Q
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from wagtail import hooks
|
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.bulk_actions.snippet_bulk_action import SnippetBulkAction
|
||||||
from wagtail.snippets.models import register_snippet
|
from wagtail.snippets.models import register_snippet
|
||||||
from wagtail.snippets.permissions import get_permission_name
|
from wagtail.snippets.permissions import get_permission_name
|
||||||
@@ -45,7 +45,13 @@ class CommentViewSet(SnippetViewSet):
|
|||||||
model = Comment
|
model = Comment
|
||||||
queryset = Comment.objects.all()
|
queryset = Comment.objects.all()
|
||||||
icon = "comment"
|
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"]
|
list_filter = ["is_approved"]
|
||||||
search_fields = ["author_name", "body"]
|
search_fields = ["author_name", "body"]
|
||||||
add_to_admin_menu = True
|
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)
|
register_snippet(CommentViewSet)
|
||||||
hooks.register("register_bulk_action", ApproveCommentBulkAction)
|
hooks.register("register_bulk_action", ApproveCommentBulkAction)
|
||||||
|
|||||||
Reference in New Issue
Block a user