diff --git a/easyaudit/signals/model_signals.py b/easyaudit/signals/model_signals.py index c5b9eb98..6556f4d2 100644 --- a/easyaudit/signals/model_signals.py +++ b/easyaudit/signals/model_signals.py @@ -54,9 +54,10 @@ def pre_save(sender, instance, raw, using, update_fields, **kwargs): return try: + if not should_audit(instance): + return False + with transaction.atomic(using=using): - if not should_audit(instance): - return False try: object_json_repr = serializers.serialize("json", [instance]) except Exception: @@ -132,9 +133,10 @@ def post_save(sender, instance, created, raw, using, update_fields, **kwargs): return try: + if not should_audit(instance): + return False + with transaction.atomic(using=using): - if not should_audit(instance): - return False object_json_repr = serializers.serialize("json", [instance]) # created or updated? @@ -211,13 +213,12 @@ def _m2m_rev_field_name(model1, model2): def m2m_changed(sender, instance, action, reverse, model, pk_set, using, **kwargs): """https://docs.djangoproject.com/es/1.10/ref/signals/#m2m-changed""" try: - with transaction.atomic(using=using): - if not should_audit(instance): - return False - - if action not in ("post_add", "post_remove", "post_clear"): - return False + if not should_audit(instance): + return False + if action not in ("post_add", "post_remove", "post_clear"): + return False + with transaction.atomic(using=using): object_json_repr = serializers.serialize("json", [instance]) if reverse: @@ -301,10 +302,10 @@ def crud_flow(): def post_delete(sender, instance, using, **kwargs): """https://docs.djangoproject.com/es/1.10/ref/signals/#post-delete""" try: - with transaction.atomic(using=using): - if not should_audit(instance): - return False + if not should_audit(instance): + return False + with transaction.atomic(using=using): object_json_repr = serializers.serialize("json", [instance]) # user