From 4b4704f639cdd76e27e51c30181a380baef005ed Mon Sep 17 00:00:00 2001 From: djperrefort Date: Tue, 6 Aug 2024 10:25:50 -0400 Subject: [PATCH] Adds admin interface for user notifications --- keystone_api/apps/notifications/admin.py | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 keystone_api/apps/notifications/admin.py diff --git a/keystone_api/apps/notifications/admin.py b/keystone_api/apps/notifications/admin.py new file mode 100644 index 00000000..7cacec4d --- /dev/null +++ b/keystone_api/apps/notifications/admin.py @@ -0,0 +1,45 @@ +"""Extends the builtin Django admin interface for the parent application. + +Extends and customizes the site-wide administration utility with +interfaces for managing application database constructs. +""" + +from django.contrib import admin + +from .models import * + +settings.JAZZMIN_SETTINGS['icons'].update({ + 'notifications.Notification': 'fa fa-envelope', + 'notifications.Preference': 'fas fa-mail-bulk', +}) + +settings.JAZZMIN_SETTINGS['order_with_respect_to'].extend([ + 'notifications.Preference', + 'notifications.Notification', +]) + + +@admin.register(Notification) +class NotificationAdmin(admin.ModelAdmin): + """Admin interface for user notifications""" + + list_display = ('user', 'notification_type', 'time', 'read') + list_filter = ('read', 'notification_type', 'time') + search_fields = ('user__username', 'message') + + def has_change_permission(self, request, obj=None) -> False: + return False + + def has_add_permission(self, request, obj=None) -> False: + return False + + def has_delete_permission(self, request, obj=None) -> False: + return False + + +@admin.register(Preference) +class PreferenceAdmin(admin.ModelAdmin): + """Admin interface for user notification preferences""" + + list_display = ('user',) + search_fields = ('user__username',)