Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def post_change_receiver(self, instance: Model, action: Action, **kwargs):
"""
Triggers the old_binding to possibly send to its group.
"""
old_group_names = self.get_observer_state(instance).current_groups
if action == Action.DELETE:
new_group_names = set()
else:
new_group_names = set(self.group_names_for_signal(instance=instance))
self.get_observer_state(instance).current_groups = new_group_names
# if post delete, new_group_names should be []
# Django DDP had used the ordering of DELETE, UPDATE then CREATE for good reasons.
self.send_messages(
instance, old_group_names - new_group_names, Action.DELETE, **kwargs
)
# the object has been updated so that its groups are not the same.
self.send_messages(
instance, old_group_names & new_group_names, Action.UPDATE, **kwargs
)
def post_delete_receiver(self, instance: Model, **kwargs):
self.database_event(instance, Action.DELETE)
"""
old_group_names = self.get_observer_state(instance).current_groups
if action == Action.DELETE:
new_group_names = set()
else:
new_group_names = set(self.group_names_for_signal(instance=instance))
self.get_observer_state(instance).current_groups = new_group_names
# if post delete, new_group_names should be []
# Django DDP had used the ordering of DELETE, UPDATE then CREATE for good reasons.
self.send_messages(
instance, old_group_names - new_group_names, Action.DELETE, **kwargs
)
# the object has been updated so that its groups are not the same.
self.send_messages(
instance, old_group_names & new_group_names, Action.UPDATE, **kwargs
)
#
self.send_messages(
instance, new_group_names - old_group_names, Action.CREATE, **kwargs
)