This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwagtail_hooks.py
57 lines (47 loc) · 1.56 KB
/
wagtail_hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django_comments.models import Comment
from django.contrib.contenttypes.models import ContentType
from django.utils.html import format_html, strip_tags
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
from .views import CommentDeleteView
class CommentAdmin(ModelAdmin):
model = Comment
menu_label = "Comments"
menu_icon = "doc-full-inverse"
add_to_settings_menu = False
delete_view_class = CommentDeleteView # new
list_display = (
"is_visible",
"plain_text_comment",
"name",
"submit_date",
"comment_page_type",
"comment_page",
)
ordering = ("-submit_date",)
search_fields = ("comment",)
list_per_page = 10
form_fields_exclude = [
"submit_date",
"ip_address",
"is_removed",
"is_public",
"user_url",
"user",
"content_type",
"object_pk",
"content_object",
"site",
]
def comment_page_type(self, obj):
ct = ContentType.objects.get(pk=obj.content_object.content_type_id)
return ct.model_class().__name__
def comment_page(self, obj):
return format_html(
f"<a href='{obj.content_object.specific.url}'>{obj.content_object.specific.title}</a>"
)
def plain_text_comment(self, obj):
return strip_tags(obj.comment)
def is_visible(self, obj):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
return _boolean_icon(not obj.is_removed)
modeladmin_register(CommentAdmin)