mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Add object type filter to audit log report
This commit is contained in:
parent
77b34458de
commit
b24a8203c9
@ -6,6 +6,7 @@ import django_filters
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import IntegerField, Value
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -25,6 +26,15 @@ def get_users_for_filter():
|
||||
User = get_user_model()
|
||||
return User.objects.filter(pk__in=user_ids).order_by(User.USERNAME_FIELD)
|
||||
|
||||
|
||||
def get_content_types_for_filter():
|
||||
content_type_ids = set()
|
||||
for log_model in log_action_registry.get_log_entry_models():
|
||||
content_type_ids.update(log_model.objects.all().get_content_type_ids())
|
||||
|
||||
return ContentType.objects.filter(pk__in=content_type_ids).order_by('model')
|
||||
|
||||
|
||||
class SiteHistoryReportFilterSet(WagtailFilterSet):
|
||||
action = django_filters.ChoiceFilter(choices=log_action_registry.get_choices)
|
||||
hide_commenting_actions = django_filters.BooleanFilter(
|
||||
@ -37,6 +47,10 @@ class SiteHistoryReportFilterSet(WagtailFilterSet):
|
||||
user = django_filters.ModelChoiceFilter(
|
||||
field_name='user', queryset=lambda request: get_users_for_filter()
|
||||
)
|
||||
object_type = django_filters.ModelChoiceFilter(
|
||||
label=_('Object type'),
|
||||
field_name='content_type', queryset=lambda request: get_content_types_for_filter()
|
||||
)
|
||||
|
||||
def filter_hide_commenting_actions(self, queryset, name, value):
|
||||
if value:
|
||||
@ -47,7 +61,7 @@ class SiteHistoryReportFilterSet(WagtailFilterSet):
|
||||
|
||||
class Meta:
|
||||
model = PageLogEntry
|
||||
fields = ['label', 'action', 'user', 'timestamp', 'hide_commenting_actions']
|
||||
fields = ['object_type', 'label', 'action', 'user', 'timestamp', 'hide_commenting_actions']
|
||||
|
||||
|
||||
class LogEntriesView(ReportView):
|
||||
|
@ -34,6 +34,12 @@ class LogEntryQuerySet(models.QuerySet):
|
||||
User = get_user_model()
|
||||
return User.objects.filter(pk__in=self.get_user_ids()).order_by(User.USERNAME_FIELD)
|
||||
|
||||
def get_content_type_ids(self):
|
||||
"""
|
||||
Returns a set of IDs of content types with logged actions in this QuerySet
|
||||
"""
|
||||
return set(self.order_by().values_list('content_type_id', flat=True).distinct())
|
||||
|
||||
|
||||
class BaseLogEntryManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
|
Loading…
Reference in New Issue
Block a user