Merge pull request #2330 from normanjaeckel/FixAutoupdate

Fixed autoupdate for deleted instances. Fixed #2329.
This commit is contained in:
Norman Jäckel 2016-08-29 16:59:28 +02:00 committed by GitHub
commit 9fdc050048

View File

@ -109,19 +109,23 @@ def inform_changed_data(instance, is_deleted=False):
# Instance has no method get_root_rest_element. Just ignore it.
pass
else:
message_dict = {
'collection_string': root_instance.get_collection_string(),
'pk': root_instance.pk,
'is_deleted': is_deleted and instance == root_instance,
'dispatch_uid': root_instance.get_access_permissions().get_dispatch_uid(),
}
# If currently there is an open database transaction, then the following
# function is only called, when the transaction is commited. If there
# is currently no transaction, then the function is called immediately.
def send_autoupdate():
def send_autoupdate(message):
try:
Channel('autoupdate.send_data').send({
'collection_string': root_instance.get_collection_string(),
'pk': root_instance.pk,
'is_deleted': is_deleted and instance == root_instance,
'dispatch_uid': root_instance.get_access_permissions().get_dispatch_uid()})
Channel('autoupdate.send_data').send(message)
except ChannelLayer.ChannelFull:
pass
transaction.on_commit(send_autoupdate)
transaction.on_commit(lambda: send_autoupdate(message_dict))
def inform_changed_data_receiver(sender, instance, **kwargs):