Coverage for website/announcements/admin.py: 88.57%
35 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1from django.contrib import admin
2from django.template.defaultfilters import striptags
4from events.admin.event import EventAdmin as BaseEventAdmin
5from events.models import Event
6from thaliawebsite.templatetags.bleach_tags import bleach
8from .models import Announcement, FrontpageArticle, Slide
11@admin.register(Announcement)
12class AnnouncementAdmin(admin.ModelAdmin):
13 """Manage the admin pages for the announcements."""
15 #: show these fields in the admin overview list
16 #: see :py:method:content_html for the 'content_html' field
17 #: see :py:method:visible for the visible field
18 list_display = ("content_html", "since", "until", "visible")
20 def content_html(self, obj):
21 """Get the content of the object as html.
23 :param obj: the object to render for
24 :return: the stripped html
25 """
26 # Both bleach and striptags.
27 # First to convert HTML entities and second to strip all HTML
28 return bleach(striptags(obj.content))
30 def visible(self, obj):
31 """Is the object visible."""
32 return obj.is_visible
34 visible.boolean = True
37@admin.register(FrontpageArticle)
38class FrontpageArticleAdmin(admin.ModelAdmin):
39 """Manage front page articles."""
41 #: available fields in the admin overview list
42 list_display = ("title", "since", "until", "visible")
44 def visible(self, obj):
45 """Is the object visible."""
46 return obj.is_visible
48 visible.boolean = True
51@admin.register(Slide)
52class SlideAdmin(admin.ModelAdmin):
53 """Manage the admin pages for the slides."""
55 #: show these fields in the admin overview list
56 #: see :py:method:visible for the visible field
57 list_display = ("title", "since", "until", "visible")
59 def visible(self, obj):
60 """Is the object visible."""
61 return obj.is_visible
63 visible.boolean = True
66class SlideInline(admin.StackedInline):
67 model = Slide
68 extra = 0
69 classes = ("collapse",)
72class EventAdmin(BaseEventAdmin):
73 def get_inlines(self, request, obj=None):
74 return [*super().get_inlines(request, obj), SlideInline]
77# Unregister the original EventAdmin and register the new one with SlideInline.
78admin.site.unregister(Event)
79admin.site.register(Event, EventAdmin)