make moveMedia async
This commit is contained in:
parent
bea661abcf
commit
3ac08aa806
4 changed files with 73 additions and 50 deletions
|
@ -4,8 +4,8 @@ from __future__ import division, print_function, absolute_import
|
||||||
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
|
from six import string_types
|
||||||
from celery.task import task
|
from celery.task import task
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
@ -201,3 +201,47 @@ def update_stream(id):
|
||||||
@task(queue="encoding")
|
@task(queue="encoding")
|
||||||
def download_media(item_id, url):
|
def download_media(item_id, url):
|
||||||
return external.download(item_id, url)
|
return external.download(item_id, url)
|
||||||
|
|
||||||
|
@task(queue='default')
|
||||||
|
def move_media(data, user):
|
||||||
|
user = models.User.objects.get(username=user)
|
||||||
|
from changelog.models import add_changelog
|
||||||
|
from item.models import get_item, Item
|
||||||
|
import item.tasks
|
||||||
|
if Item.objects.filter(public_id=data['item']).count() == 1:
|
||||||
|
i = Item.objects.get(public_id=data['item'])
|
||||||
|
else:
|
||||||
|
data['public_id'] = data.pop('item').strip()
|
||||||
|
if len(data['public_id']) != 7:
|
||||||
|
del data['public_id']
|
||||||
|
if 'director' in data and isinstance(data['director'], string_types):
|
||||||
|
if data['director'] == '':
|
||||||
|
data['director'] = []
|
||||||
|
else:
|
||||||
|
data['director'] = data['director'].split(', ')
|
||||||
|
i = get_item(data, user=user)
|
||||||
|
else:
|
||||||
|
i = get_item({'imdbId': data['public_id']}, user=user)
|
||||||
|
changed = [i.public_id]
|
||||||
|
for f in models.File.objects.filter(oshash__in=data['ids']):
|
||||||
|
if f.item.id != i.public_id and f.editable(user):
|
||||||
|
if f.item.public_id not in changed:
|
||||||
|
changed.append(f.item.public_id)
|
||||||
|
f.item = i
|
||||||
|
f.save()
|
||||||
|
for public_id in changed:
|
||||||
|
c = Item.objects.get(public_id=public_id)
|
||||||
|
if c.files.count() == 0 and settings.CONFIG['itemRequiresVideo']:
|
||||||
|
c.delete()
|
||||||
|
else:
|
||||||
|
c.rendered = False
|
||||||
|
c.save()
|
||||||
|
Task.start(c, user)
|
||||||
|
item.tasks.update_timeline.delay(public_id)
|
||||||
|
add_changelog({
|
||||||
|
'user': user,
|
||||||
|
'action': 'moveMedia'
|
||||||
|
}, data, i.public_id)
|
||||||
|
return {
|
||||||
|
'item': i.public_id
|
||||||
|
}
|
||||||
|
|
|
@ -378,9 +378,12 @@ def getTaskStatus(request, data):
|
||||||
res = default_backend.get_result(task_id)
|
res = default_backend.get_result(task_id)
|
||||||
response['data'] = {
|
response['data'] = {
|
||||||
'id': task_id,
|
'id': task_id,
|
||||||
'status': status,
|
'status': status
|
||||||
'result': res
|
|
||||||
}
|
}
|
||||||
|
if isinstance(res, dict):
|
||||||
|
response['data'].update(res)
|
||||||
|
else:
|
||||||
|
response['data']['result'] = res
|
||||||
if status in default_backend.EXCEPTION_STATES:
|
if status in default_backend.EXCEPTION_STATES:
|
||||||
traceback = default_backend.get_traceback(task_id)
|
traceback = default_backend.get_traceback(task_id)
|
||||||
response['data'].update({
|
response['data'].update({
|
||||||
|
@ -405,39 +408,9 @@ def moveMedia(request, data):
|
||||||
notes: This will *not* (yet) shift the corresponding annotations.
|
notes: This will *not* (yet) shift the corresponding annotations.
|
||||||
see: addMedia, editMedia, findMedia, removeMedia
|
see: addMedia, editMedia, findMedia, removeMedia
|
||||||
'''
|
'''
|
||||||
if Item.objects.filter(public_id=data['item']).count() == 1:
|
response = json_response()
|
||||||
i = Item.objects.get(public_id=data['item'])
|
t = tasks.move_media.delay(data, request.user.username)
|
||||||
else:
|
response['data']['taskId'] = t.task_id
|
||||||
data['public_id'] = data.pop('item').strip()
|
|
||||||
if len(data['public_id']) != 7:
|
|
||||||
del data['public_id']
|
|
||||||
if 'director' in data and isinstance(data['director'], string_types):
|
|
||||||
if data['director'] == '':
|
|
||||||
data['director'] = []
|
|
||||||
else:
|
|
||||||
data['director'] = data['director'].split(', ')
|
|
||||||
i = get_item(data, user=request.user)
|
|
||||||
else:
|
|
||||||
i = get_item({'imdbId': data['public_id']}, user=request.user)
|
|
||||||
changed = [i.public_id]
|
|
||||||
for f in models.File.objects.filter(oshash__in=data['ids']):
|
|
||||||
if f.item.id != i.public_id and f.editable(request.user):
|
|
||||||
if f.item.public_id not in changed:
|
|
||||||
changed.append(f.item.public_id)
|
|
||||||
f.item = i
|
|
||||||
f.save()
|
|
||||||
for public_id in changed:
|
|
||||||
c = Item.objects.get(public_id=public_id)
|
|
||||||
if c.files.count() == 0 and settings.CONFIG['itemRequiresVideo']:
|
|
||||||
c.delete()
|
|
||||||
else:
|
|
||||||
c.rendered = False
|
|
||||||
c.save()
|
|
||||||
Task.start(c, request.user)
|
|
||||||
item.tasks.update_timeline.delay(public_id)
|
|
||||||
response = json_response(text='updated')
|
|
||||||
response['data']['item'] = i.public_id
|
|
||||||
add_changelog(request, data, i.public_id)
|
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(moveMedia, cache=False)
|
actions.register(moveMedia, cache=False)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@ class Changelog(models.Model):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def add_changelog(request, data, id=None):
|
def add_changelog(request, data, id=None):
|
||||||
|
if isinstance(request, dict):
|
||||||
|
user = request['user']
|
||||||
|
action = request['action']
|
||||||
|
else:
|
||||||
user = request.user
|
user = request.user
|
||||||
action = request.POST['action']
|
action = request.POST['action']
|
||||||
c = Log(user=user, action=action, data=data)
|
c = Log(user=user, action=action, data=data)
|
||||||
|
|
|
@ -550,6 +550,7 @@ pandora.ui.mediaView = function(options) {
|
||||||
{disabled: true, title: Ox._('Moving Files...')}
|
{disabled: true, title: Ox._('Moving Files...')}
|
||||||
);
|
);
|
||||||
pandora.api.moveMedia(data, function(result) {
|
pandora.api.moveMedia(data, function(result) {
|
||||||
|
pandora.wait(result.data.taskId, function(result) {
|
||||||
if (isActive()) {
|
if (isActive()) {
|
||||||
Ox.Request.clearCache(); // fixme: remove
|
Ox.Request.clearCache(); // fixme: remove
|
||||||
if (self.$switch.value()) {
|
if (self.$switch.value()) {
|
||||||
|
@ -564,6 +565,7 @@ pandora.ui.mediaView = function(options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openFiles(data) {
|
function openFiles(data) {
|
||||||
|
|
Loading…
Reference in a new issue