From 4ae1b827f58991f75a4c58e9def970b23f02c495 Mon Sep 17 00:00:00 2001 From: soynatan Date: Sat, 28 Jan 2017 20:58:52 -0300 Subject: [PATCH] Setting names --- README.md | 14 +++++++------- easyaudit/settings.py | 15 +++++++++------ easyaudit/signals.py | 8 +++++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 013e8294..ba6a6787 100644 --- a/README.md +++ b/README.md @@ -44,18 +44,18 @@ you can define the following settings: Set to `False` it won't log your project's login events (log in, log out, and failed logins). Defaults to `True`. -* `DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES` +* `DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_DEFAULT` + + The default list of classes django-easy-audit will ignore. Don't override this setting + unless you know what you are doing; it may create an infinite loop and break your project. + If you want django-easy-audit to stop logging one of your models please use the following setting. + +* `DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_EXTRA` A list of classes django-easy-audit will ignore. Use it to avoid logging some of your project's models if necessary. It can be a class or a string with `app_name.model_name` format. Defaults to `[]`. -* `DJANGO_EASY_AUDIT_DEFAULT_UNREGISTERED_CLASSES` - - The default list of classes django-easy-audit will ignore. Don't override this setting - unless you know what you are doing; it may create an infinite loop and break your project. - If you want django-easy-audit to stop logging one of your models please use previous setting. - ## What does it do django-easy-audit uses [Django signals](https://docs.djangoproject.com/en/dev/topics/signals/) diff --git a/easyaudit/settings.py b/easyaudit/settings.py index 9e5ce58a..3ae68cfd 100644 --- a/easyaudit/settings.py +++ b/easyaudit/settings.py @@ -12,22 +12,25 @@ from easyaudit.models import CRUDEvent, LoginEvent -# unregistered classes +# default unregistered classes UNREGISTERED_CLASSES = [CRUDEvent, LoginEvent, Migration, LogEntry, Session, Permission, ContentType, MigrationRecorder.Migration] -# see if the project settings differ -UNREGISTERED_CLASSES = getattr(settings, 'DJANGO_EASY_AUDIT_DEFAULT_UNREGISTERED_CLASSES', UNREGISTERED_CLASSES) -# if the project has classes that they don't want registered, but want the original set, but don't want to import them -# then they can use the APPEND setting. -UNREGISTERED_CLASSES.extend(getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_APPEND', [])) + +# override default unregistered classes if defined in project settings +UNREGISTERED_CLASSES = getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_DEFAULT', UNREGISTERED_CLASSES) + +# extra unregistered classes +UNREGISTERED_CLASSES.extend(getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_EXTRA', [])) for idx, item in enumerate(UNREGISTERED_CLASSES): if isinstance(item, six.string_types): model_class = apps.get_model(item) UNREGISTERED_CLASSES[idx] = model_class +# should login events be registered? WATCH_LOGIN_EVENTS = getattr(settings, 'DJANGO_EASY_AUDIT_WATCH_LOGIN_EVENTS', True) +# project defined callbacks CRUD_DIFFERENCE_CALLBACKS = [] CRUD_DIFFERENCE_CALLBACKS = getattr(settings, 'DJANGO_EASY_AUDIT_CRUD_DIFFERENCE_CALLBACKS', CRUD_DIFFERENCE_CALLBACKS) # the callbacks could come in as an iterable of strings, where each string is the package.module.function diff --git a/easyaudit/signals.py b/easyaudit/signals.py index 201858d8..bae8b251 100644 --- a/easyaudit/signals.py +++ b/easyaudit/signals.py @@ -36,12 +36,14 @@ def post_save(sender, instance, created, raw, using, update_fields, **kwargs): if isinstance(user, AnonymousUser): user = None - kwargs['request'] = getattr(EasyAuditMiddleware, 'request', None) # the callbacks may want the request - # if one of them is False, then we do not create + + # callbacks + kwargs['request'] = getattr(EasyAuditMiddleware, 'request', None) # make request available for callbacks create_crud_event = all(callback(instance, object_json_repr, created, raw, using, update_fields, **kwargs) for callback in CRUD_DIFFERENCE_CALLBACKS if callable(callback)) + + # create crud event only if all callbacks returned True if create_crud_event: - # crud event crud_event = CRUDEvent.objects.create( event_type=event_type, object_repr=str(instance),