|
|
|
@ -5,6 +5,7 @@ import uuid
|
|
|
|
|
from django.apps import apps |
|
|
|
|
from django.db.models.signals import post_save, pre_save, m2m_changed, pre_delete |
|
|
|
|
from django.dispatch import receiver |
|
|
|
|
from django.utils import translation |
|
|
|
|
|
|
|
|
|
from audits.handler import ( |
|
|
|
|
get_instance_current_with_cache_diff, cache_instance_before_data, |
|
|
|
@ -29,6 +30,7 @@ def on_m2m_changed(sender, action, instance, reverse, model, pk_set, **kwargs):
|
|
|
|
|
if not instance: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
with translation.override('en'): |
|
|
|
|
resource_type = instance._meta.verbose_name |
|
|
|
|
current_instance = model_to_dict(instance, include_model_fields=False) |
|
|
|
|
|
|
|
|
@ -93,7 +95,7 @@ def on_object_pre_create_or_update(
|
|
|
|
|
) |
|
|
|
|
if not ok: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
with translation.override('en'): |
|
|
|
|
# users.PrivateToken Model 没有 id 有 pk字段 |
|
|
|
|
instance_id = getattr(instance, 'id', getattr(instance, 'pk', None)) |
|
|
|
|
instance_before_data = {'id': instance_id} |
|
|
|
@ -116,7 +118,7 @@ def on_object_created_or_update(
|
|
|
|
|
) |
|
|
|
|
if not ok: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
with translation.override('en'): |
|
|
|
|
log_id, before, after = None, None, None |
|
|
|
|
if created: |
|
|
|
|
action = ActionChoices.create |
|
|
|
@ -141,6 +143,7 @@ def on_object_delete(sender, instance=None, **kwargs):
|
|
|
|
|
if not ok: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
with translation.override('en'): |
|
|
|
|
resource_type = sender._meta.verbose_name |
|
|
|
|
create_or_update_operate_log( |
|
|
|
|
ActionChoices.delete, resource_type, |
|
|
|
|