Skip to content

Commit

Permalink
Allow filtering by log level in TimelineLogLevel admin
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Oct 15, 2024
1 parent 63d98be commit 7c66783
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/open_inwoner/utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ 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.upper()) for v in logging.getLevelNamesMapping().keys()]

def queryset(self, request, queryset):
if not (value := self.value()):
return queryset

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"]
Expand All @@ -74,7 +92,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",
Expand Down

0 comments on commit 7c66783

Please sign in to comment.