|
|
|
|
@ -13,13 +13,15 @@ User = get_user_model() |
|
|
|
|
@receiver([pre_save, pre_delete]) |
|
|
|
|
def synchronization_prepare(sender, instance, created=False, **kwargs): |
|
|
|
|
|
|
|
|
|
# some classes are excluded in settings_app.py: SYNC_APPS |
|
|
|
|
# some other classes are excluded in settings_app.py: SYNC_APPS |
|
|
|
|
if not isinstance(instance, BaseModel) and not isinstance(instance, User): |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
save_model_log_if_possible(instance, kwargs.get('signal'), created) |
|
|
|
|
|
|
|
|
|
@receiver(pre_save) |
|
|
|
|
if kwargs.get('signal') == pre_save: |
|
|
|
|
detect_foreign_key_changes(sender, instance) |
|
|
|
|
|
|
|
|
|
def detect_foreign_key_changes(sender, instance, **kwargs): |
|
|
|
|
if not hasattr(instance, 'pk') or not instance.pk: |
|
|
|
|
return |
|
|
|
|
@ -47,7 +49,6 @@ def detect_foreign_key_changes(sender, instance, **kwargs): |
|
|
|
|
model_name = new_value.__class__.__name__ |
|
|
|
|
save_model_log(data_access.shared_with.all(), 'GRANT_ACCESS', model_name, new_value.id, new_value.get_store_id()) |
|
|
|
|
|
|
|
|
|
# def save_model_log(users, model_operation, model_name, model_id, store_id): |
|
|
|
|
# REVOKE access for old_value and GRANT new_value |
|
|
|
|
print(f"Foreign key changed in {sender.__name__}: " |
|
|
|
|
f"{field.name} from {old_value} to {new_value}") |
|
|
|
|
@ -61,7 +62,7 @@ def synchronization_notifications(sender, instance, created=False, **kwargs): |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
# some classes are excluded in settings_app.py: SYNC_APPS |
|
|
|
|
if not isinstance(instance, BaseModel): |
|
|
|
|
if not isinstance(instance, BaseModel) and not isinstance(instance, User): |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
# print(f'*** signals {sender}') |
|
|
|
|
|