11from importlib import import_module
22
3- from django .apps . registry import apps
3+ from django .apps import apps
44from django .conf import settings
5- from django .contrib .admin .models import LogEntry
65from django .contrib .auth .models import Permission
76from django .contrib .contenttypes .models import ContentType
87from django .contrib .sessions .models import Session
@@ -31,12 +30,20 @@ def get_model_list(class_list):
3130WATCH_REQUEST_EVENTS = getattr (settings , 'DJANGO_EASY_AUDIT_WATCH_REQUEST_EVENTS' , True )
3231REMOTE_ADDR_HEADER = getattr (settings , 'DJANGO_EASY_AUDIT_REMOTE_ADDR_HEADER' , 'REMOTE_ADDR' )
3332
33+ USER_DB_CONSTRAINT = bool (getattr (settings , 'DJANGO_EASY_AUDIT_USER_DB_CONSTRAINT' , True ))
34+
3435
3536# Models which Django Easy Audit will not log.
3637# By default, all but some models will be audited.
3738# The list of excluded models can be overwritten or extended
3839# by defining the following settings in the project.
39- UNREGISTERED_CLASSES = [CRUDEvent , LoginEvent , RequestEvent , Migration , LogEntry , Session , Permission , ContentType , MigrationRecorder .Migration ]
40+ UNREGISTERED_CLASSES = [CRUDEvent , LoginEvent , RequestEvent , Migration , Session , Permission , ContentType , MigrationRecorder .Migration ]
41+
42+ # Import and unregister LogEntry class only if Django Admin app is installed
43+ if apps .is_installed ('django.contrib.admin' ):
44+ from django .contrib .admin .models import LogEntry
45+ UNREGISTERED_CLASSES += [LogEntry ]
46+
4047UNREGISTERED_CLASSES = getattr (settings , 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_DEFAULT' , UNREGISTERED_CLASSES )
4148UNREGISTERED_CLASSES .extend (getattr (settings , 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_EXTRA' , []))
4249get_model_list (UNREGISTERED_CLASSES )
@@ -60,6 +67,13 @@ def get_model_list(class_list):
6067UNREGISTERED_URLS .extend (getattr (settings , 'DJANGO_EASY_AUDIT_UNREGISTERED_URLS_EXTRA' , []))
6168
6269
70+ # URLs which Django Easy Audit WILL log.
71+ # If the following setting is defined in the project,
72+ # only the listed URLs will be audited, and every other
73+ # URL will be excluded.
74+ REGISTERED_URLS = getattr (settings , 'DJANGO_EASY_AUDIT_REGISTERED_URLS' , [])
75+
76+
6377# By default all modules are listed in the admin.
6478# This can be changed with the following settings.
6579ADMIN_SHOW_MODEL_EVENTS = getattr (settings , 'DJANGO_EASY_AUDIT_ADMIN_SHOW_MODEL_EVENTS' , True )
0 commit comments