diff --git a/requirements/base.txt b/requirements/base.txt index fe1268cae5..6ed35615e9 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -273,7 +273,7 @@ django-solo==2.2.0 # mozilla-django-oidc-db # notifications-api-common # zgw-consumers -django-timeline-logger==3.0.0 +django-timeline-logger==4.0.0 # via -r requirements/base.in django-timezone-field==6.1.0 # via django-celery-beat diff --git a/requirements/ci.txt b/requirements/ci.txt index 0d8eb2936b..e3367bfd2f 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -461,7 +461,7 @@ django-solo==2.2.0 # mozilla-django-oidc-db # notifications-api-common # zgw-consumers -django-timeline-logger==3.0.0 +django-timeline-logger==4.0.0 # via # -c requirements/base.txt # -r requirements/base.txt diff --git a/requirements/dev.txt b/requirements/dev.txt index fccd6333bd..e09348501c 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -507,7 +507,7 @@ django-solo==2.2.0 # mozilla-django-oidc-db # notifications-api-common # zgw-consumers -django-timeline-logger==3.0.0 +django-timeline-logger==4.0.0 # via # -c requirements/ci.txt # -r requirements/ci.txt diff --git a/src/open_inwoner/utils/admin.py b/src/open_inwoner/utils/admin.py index 92b5fb9d6b..b744a8a375 100644 --- a/src/open_inwoner/utils/admin.py +++ b/src/open_inwoner/utils/admin.py @@ -4,6 +4,7 @@ from django.contrib import admin from django.contrib.admin.models import ADDITION, CHANGE, DELETION from django.contrib.contenttypes.models import ContentType +from django.db.models import Q from django.shortcuts import get_object_or_404, redirect from django.urls import NoReverseMatch, path, reverse from django.utils.html import escape, format_html @@ -62,6 +63,32 @@ def queryset(self, request, queryset): return queryset +class TimelineLogLevelFilter(admin.SimpleListFilter): + title = _("log level") + parameter_name = "log_level" + + def lookups(self, request, model_admin): + return [(v, v) for v in logging.getLevelNamesMapping().keys()] + [ + ("unknown", _("Unknown")) + ] + + def queryset(self, request, queryset): + if not (value := self.value()): + return queryset + + if value == "unknown": + return queryset.filter( + ~Q(extra_data__has_key="log_level") + | Q(extra_data__log_level__isnull=True) + ) + + try: + log_level = logging.getLevelNamesMapping()[value] + return queryset.filter(extra_data__log_level=log_level) + except KeyError: + return queryset + + class CustomTimelineLogAdmin(ExportMixin, TimelineLogAdmin): show_full_result_count = False fields = ["content_type", "timestamp", "extra_data", "user"] @@ -74,7 +101,12 @@ class CustomTimelineLogAdmin(ExportMixin, TimelineLogAdmin): "get_action_flag", "message", ] - list_filter = ["timestamp", LogActionListFilter, ContentTypeUsedListFilter] + list_filter = [ + "timestamp", + TimelineLogLevelFilter, + LogActionListFilter, + ContentTypeUsedListFilter, + ] list_select_related = ["content_type"] search_fields = [ "user__email",