Fix and improvement

sync
Laurent 11 months ago
parent 8916ddbbeb
commit 4a8d7c6a5c
  1. 9
      sync/signals.py

@ -13,13 +13,15 @@ User = get_user_model()
@receiver([pre_save, pre_delete]) @receiver([pre_save, pre_delete])
def synchronization_prepare(sender, instance, created=False, **kwargs): 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): if not isinstance(instance, BaseModel) and not isinstance(instance, User):
return return
save_model_log_if_possible(instance, kwargs.get('signal'), created) 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): def detect_foreign_key_changes(sender, instance, **kwargs):
if not hasattr(instance, 'pk') or not instance.pk: if not hasattr(instance, 'pk') or not instance.pk:
return return
@ -47,7 +49,6 @@ def detect_foreign_key_changes(sender, instance, **kwargs):
model_name = new_value.__class__.__name__ 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()) 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 # REVOKE access for old_value and GRANT new_value
print(f"Foreign key changed in {sender.__name__}: " print(f"Foreign key changed in {sender.__name__}: "
f"{field.name} from {old_value} to {new_value}") 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 # 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 return
# print(f'*** signals {sender}') # print(f'*** signals {sender}')

Loading…
Cancel
Save