async annotation import

This commit is contained in:
j 2018-12-31 14:48:10 +01:00
parent 01f32871fd
commit 4e0c73c2fa

View file

@ -12,7 +12,7 @@ import app.monkey_patch
from item.models import Item from item.models import Item
from ... import models from ... import models, tasks
User = get_user_model() User = get_user_model()
@ -22,12 +22,12 @@ class Command(BaseCommand):
import annotations import annotations
""" """
help = 'import annotations from srt or vtt' help = 'import annotations from srt or vtt'
args = 'username item layername filename.srt' args = 'username item layer filename.srt'
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('username', help='username') parser.add_argument('username', help='username')
parser.add_argument('item', help='item') parser.add_argument('item', help='item')
parser.add_argument('layername', help='layer') parser.add_argument('layer', help='layer')
parser.add_argument('filename', help='filename.srt') parser.add_argument('filename', help='filename.srt')
def handle(self, *args, **options): def handle(self, *args, **options):
@ -48,22 +48,9 @@ class Command(BaseCommand):
for i in range(len(annotations)-1): for i in range(len(annotations)-1):
if annotations[i]['out'] == annotations[i+1]['in']: if annotations[i]['out'] == annotations[i+1]['in']:
annotations[i]['out'] = annotations[i]['out'] - 0.001 annotations[i]['out'] = annotations[i]['out'] - 0.001
with transaction.atomic(): tasks.add_annotations.delay({
for a in annotations: 'item': item.public_id,
if a['value']: 'layer': layer_id,
annotation = models.Annotation( 'user': username,
item=item, 'annotations': annotations
layer=layer_id, })
user=user,
start=float(a['in']),
end=float(a['out']),
value=a['value'])
annotation.save()
#update facets if needed
if list(filter(lambda f: f['id'] == layer_id, settings.CONFIG['filters'])):
item.update_layer_facet(layer_id)
Item.objects.filter(id=item.id).update(modified=annotation.modified)
annotation.item.modified = annotation.modified
annotation.item.update_find()
annotation.item.update_sort()
annotation.item.update_facets()