Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): add event list_display to settings #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions easyaudit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .models import CRUDEvent, LoginEvent, RequestEvent
from .admin_helpers import prettify_json, EasyAuditModelAdmin
from .settings import (CRUD_EVENT_LIST_FILTER, LOGIN_EVENT_LIST_FILTER, REQUEST_EVENT_LIST_FILTER,
CRUD_EVENT_LIST_DISPLAY, LOGIN_EVENT_LIST_DISPLAY, REQUEST_EVENT_LIST_DISPLAY,
CRUD_EVENT_SEARCH_FIELDS, LOGIN_EVENT_SEARCH_FIELDS, REQUEST_EVENT_SEARCH_FIELDS,
READONLY_EVENTS)

Expand Down Expand Up @@ -44,7 +45,7 @@ def export_to_csv(modeladmin, request, queryset):

# CRUD events
class CRUDEventAdmin(EasyAuditModelAdmin):
list_display = ['get_event_type_display', 'get_content_type', 'object_id', 'object_repr_link', 'user_link', 'datetime']
list_display = CRUD_EVENT_LIST_DISPLAY
date_hierarchy = 'datetime'
list_filter = CRUD_EVENT_LIST_FILTER
search_fields = CRUD_EVENT_SEARCH_FIELDS
Expand Down Expand Up @@ -105,7 +106,7 @@ def changed_fields_prettified(self, obj):

# Login events
class LoginEventAdmin(EasyAuditModelAdmin):
list_display = ['datetime', 'get_login_type_display', 'user_link', "get_username", 'remote_ip']
list_display = LOGIN_EVENT_LIST_DISPLAY
date_hierarchy = 'datetime'
list_filter = LOGIN_EVENT_LIST_FILTER
search_fields = LOGIN_EVENT_SEARCH_FIELDS
Expand All @@ -131,7 +132,7 @@ def get_username(self, obj):

# Request events
class RequestEventAdmin(EasyAuditModelAdmin):
list_display = ['datetime', 'user_link', 'method', 'url', 'remote_ip']
list_display = REQUEST_EVENT_LIST_DISPLAY
date_hierarchy = 'datetime'
list_filter = REQUEST_EVENT_LIST_FILTER
search_fields = REQUEST_EVENT_SEARCH_FIELDS
Expand Down
5 changes: 5 additions & 0 deletions easyaudit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def get_model_list(class_list):
# which is however much costly when many rows are involved
TRUNCATE_TABLE_SQL_STATEMENT = getattr(settings, 'DJANGO_EASY_AUDIT_TRUNCATE_TABLE_SQL_STATEMENT', '')

# Listview display configuration
CRUD_EVENT_LIST_DISPLAY = getattr(settings, 'DJANGO_EASY_AUDIT_CRUD_EVENT_LIST_DISPLAY', ['event_type', 'content_type', 'object_id', 'object_repr', 'user', 'datetime'])
LOGIN_EVENT_LIST_DISPLAY = getattr(settings, 'DJANGO_EASY_AUDIT_LOGIN_EVENT_LIST_DISPLAY', ['datetime', 'get_login_type_display', 'user_link', "get_username", 'remote_ip'])
REQUEST_EVENT_LIST_DISPLAY = getattr(settings, 'DJANGO_EASY_AUDIT_REQUEST_EVENT_LIST_DISPLAY', ['datetime', 'user_link', 'method', 'url', 'remote_ip'])

# Changeview filters configuration
CRUD_EVENT_LIST_FILTER = getattr(settings, 'DJANGO_EASY_AUDIT_CRUD_EVENT_LIST_FILTER', ['event_type', 'content_type', 'user', 'datetime', ])
LOGIN_EVENT_LIST_FILTER = getattr(settings, 'DJANGO_EASY_AUDIT_LOGIN_EVENT_LIST_FILTER', ['login_type', 'user', 'datetime', ])
Expand Down