From 8c9232ace9343dd897c31adfa73cdff4ded5db42 Mon Sep 17 00:00:00 2001 From: Muhammad Adeel Tajamul <77053848+muhammadadeeltajamul@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:14:32 +0500 Subject: [PATCH] feat: updated notification admin (#33320) --- .../core/djangoapps/notifications/admin.py | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/notifications/admin.py b/openedx/core/djangoapps/notifications/admin.py index 9fd69af219e..52a758b97b0 100644 --- a/openedx/core/djangoapps/notifications/admin.py +++ b/openedx/core/djangoapps/notifications/admin.py @@ -3,17 +3,61 @@ """ from django.contrib import admin +from django.utils.translation import gettext_lazy as _ +from .base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES from .models import CourseNotificationPreference, Notification +class NotificationAppNameListFilter(admin.SimpleListFilter): + """ + Shows list filter in django admin of notification apps + """ + title = _("Notification App") + parameter_name = "app_name" + + def lookups(self, request, model_admin): + lookup_list = [ + (app_name, app_name) + for app_name in COURSE_NOTIFICATION_APPS.keys() + ] + return lookup_list + + def queryset(self, request, queryset): + app_name = self.value() + if app_name not in COURSE_NOTIFICATION_APPS.keys(): + return queryset + return queryset.filter(app_name=app_name) + + +class NotificationTypeListFilter(admin.SimpleListFilter): + """ + Shows list filter in django admin of notification types + """ + title = _("Notification Type") + parameter_name = "notification_type" + + def lookups(self, request, model_admin): + lookup_list = [ + (notification_type, notification_type) + for notification_type in COURSE_NOTIFICATION_TYPES.keys() + ] + return lookup_list + + def queryset(self, request, queryset): + notification_type = self.value() + if notification_type not in COURSE_NOTIFICATION_TYPES.keys(): + return queryset + return queryset.filter(notification_type=notification_type) + + class NotificationAdmin(admin.ModelAdmin): """ Admin for Notifications """ raw_id_fields = ('user',) - search_fields = ('course_id', 'user__username') - list_filter = ('app_name',) + search_fields = ('course_id', 'app_name', 'notification_type', 'user__username') + list_filter = (NotificationAppNameListFilter, NotificationTypeListFilter) class CourseNotificationPreferenceAdmin(admin.ModelAdmin):