Skip to content

Commit

Permalink
Setting names
Browse files Browse the repository at this point in the history
  • Loading branch information
soynatan committed Jan 28, 2017
1 parent fa7441b commit 4ae1b82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
15 changes: 9 additions & 6 deletions easyaudit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions easyaudit/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 4ae1b82

Please sign in to comment.