From 4d9761a32cd0e2adf69b205ce40ba089a4697d0c Mon Sep 17 00:00:00 2001 From: j Date: Wed, 7 Sep 2016 20:16:25 +0200 Subject: [PATCH] make update_external async --- pandora/item/views.py | 7 +++++-- static/js/infoView.0xdb.js | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pandora/item/views.py b/pandora/item/views.py index 3ce0c84cc..8fd13d658 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -693,7 +693,9 @@ def updateExternalData(request, data): takes { id: string // item id } - returns {} + returns { + taskId: string, // taskId + } notes: This can be used to populate metadata from a remote source, like IMDb. see: getIds, getMetadata @@ -701,7 +703,8 @@ def updateExternalData(request, data): item = get_object_or_404_json(models.Item, public_id=data['id']) response = json_response() if item.editable(request.user): - item.update_external() + t = tasks.update_external.delay(item.public_id) + response['taskId'] = t.task_id else: response = json_response(status=403, text='permission denied') return render_to_json_response(response) diff --git a/static/js/infoView.0xdb.js b/static/js/infoView.0xdb.js index 266a5d75e..5f1582efb 100644 --- a/static/js/infoView.0xdb.js +++ b/static/js/infoView.0xdb.js @@ -1123,14 +1123,16 @@ pandora.ui.infoView = function(data) { pandora.api.updateExternalData({ id: ui.item }, function(result) { - pandora.updateItemContext(); - Ox.Request.clearCache(); - if (ui.item == item && ui.itemView == 'info') { - pandora.$ui.contentPanel.replaceElement( - 1, pandora.$ui.item = pandora.ui.item() - ); - } - $options.enableItem('update'); + (result.data.taskId ? pandora.wait : Ox.noop)(result.data.taskId, function(result) { + pandora.updateItemContext(); + Ox.Request.clearCache(); + if (ui.item == item && ui.itemView == 'info') { + pandora.$ui.contentPanel.replaceElement( + 1, pandora.$ui.item = pandora.ui.item() + ); + } + $options.enableItem('update'); + }); }); }