Add custom django CustomNotificationAdmin

This commit is contained in:
Daniel Egger 2023-08-30 13:41:06 +02:00
parent d8bce90b8e
commit b26ec64edb
4 changed files with 44 additions and 4 deletions

View File

@ -120,11 +120,10 @@ RUN chown django:django ${APP_HOME}
USER django
# pip install under the user django, the scripts will be in /home/django/.local/bin
RUN pip install supervisor
RUN exit
COPY ./compose/django/supervisord.conf /app/supervisord.conf
EXPOSE 7555
COPY ./compose/django/supervisord.conf /app/supervisord.conf
ENTRYPOINT ["/entrypoint"]

View File

@ -0,0 +1,26 @@
from vbv_lernwelt.core.admin import LogAdmin
# admin.register in apps.py
class CustomNotificationAdmin(LogAdmin):
date_hierarchy = "timestamp"
raw_id_fields = ("recipient",)
list_display = (
"recipient",
"actor",
"notification_type",
"emailed",
"unread",
)
list_filter = (
"notification_type",
"emailed",
"unread",
"timestamp",
"level",
"public",
)
def get_queryset(self, request):
qs = super(CustomNotificationAdmin, self).get_queryset(request)
return qs.prefetch_related("actor")

View File

@ -1,6 +1,20 @@
from django.apps import AppConfig
from django.contrib import admin
class NotifyConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "vbv_lernwelt.notify"
def ready(self):
# Move the admin import here to avoid early imports
from .admin import CustomNotificationAdmin
# Unregister the default Notification admin if it exists
from vbv_lernwelt.notify.models import Notification
if admin.site.is_registered(Notification):
admin.site.unregister(Notification)
# Register the custom admin
admin.site.register(Notification, CustomNotificationAdmin)

View File

@ -125,7 +125,8 @@ class TestNotificationService(TestCase):
self.assertEqual(target_url, notification.target_url)
self.assertEqual(course, notification.course)
self.assertEqual(
str(NotificationType.USER_INTERACTION), notification.notification_type
str(NotificationType.USER_INTERACTION),
notification.notification_type,
)
self.assertTrue(notification.emailed)