def push(request, video_id): video = Video.objects.get(pk=video_id) if request.method == 'POST': push_type = request.POST.get('push_type') server = VDNServer.objects.get(pk=request.POST.get('server_pk')) token = request.POST.get('token_{}'.format(server.pk)) server.last_token = token server.save() server_url = server.url if not server_url.endswith('/'): server_url += '/' headers = {'Authorization': 'Token {}'.format(server.last_token)} if push_type == 'annotation': new_vdn_dataset = create_child_vdn_dataset(video, server, headers) for key in request.POST: if key.startswith('annotation_') and request.POST[key]: annotation = Region.objects.get(pk=int(key.split('annotation_')[1])) data = { 'label': annotation.label, 'metadata_text': annotation.metadata_text, 'x': annotation.x, 'y': annotation.y, 'w': annotation.w, 'h': annotation.h, 'full_frame': annotation.full_frame, 'parent_frame_index': annotation.parent_frame_index, 'dataset_id': int(new_vdn_dataset.url.split('/')[-2]), } r = requests.post("{}/api/annotations/".format(server_url), data=data, headers=headers) if r.status_code == 201: annotation.vdn_dataset = new_vdn_dataset annotation.save() else: raise ValueError elif push_type == 'dataset': key = request.POST.get('key') region = request.POST.get('region') bucket = request.POST.get('bucket') name = request.POST.get('name') description = request.POST.get('description') s3export = TEvent() s3export.event_type = TEvent.S3EXPORT s3export.video = video s3export.key = key s3export.bucket = bucket s3export.save() create_root_vdn_dataset(s3export, server, headers, name, description) task_name = 'push_video_to_vdn_s3' app.send_task(task_name, args=[s3export.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name]) else: raise NotImplementedError servers = VDNServer.objects.all() context = {'video': video, 'servers': servers} if video.vdn_dataset: context['annotations'] = Region.objects.all().filter(video=video, vdn_dataset__isnull=True, region_type=Region.ANNOTATION) else: context['annotations'] = Region.objects.all().filter(video=video, region_type=Region.ANNOTATION) return render(request, 'push.html', context)
def push(request, video_id): video = Video.objects.get(pk=video_id) if request.method == 'POST': push_type = request.POST.get('push_type') server = VDNServer.objects.get(pk=request.POST.get('server_pk')) token = request.POST.get('token_{}'.format(server.pk)) server.last_token = token server.save() server_url = server.url if not server_url.endswith('/'): server_url += '/' headers = {'Authorization': 'Token {}'.format(server.last_token)} if push_type == 'annotation': new_vdn_dataset = create_child_vdn_dataset(video, server, headers) for key in request.POST: if key.startswith('annotation_') and request.POST[key]: annotation = Region.objects.get(pk=int(key.split('annotation_')[1])) data = { 'label': annotation.label, 'metadata_text': annotation.metadata_text, 'x': annotation.x, 'y': annotation.y, 'w': annotation.w, 'h': annotation.h, 'full_frame': annotation.full_frame, 'parent_frame_index': annotation.parent_frame_index, 'dataset_id': int(new_vdn_dataset.url.split('/')[-2]), } r = requests.post("{}/api/annotations/".format(server_url), data=data, headers=headers) if r.status_code == 201: annotation.vdn_dataset = new_vdn_dataset annotation.save() else: raise ValueError elif push_type == 'dataset': key = request.POST.get('key') region = request.POST.get('region') bucket = request.POST.get('bucket') name = request.POST.get('name') description = request.POST.get('description') s3export = TEvent() s3export.event_type = TEvent.S3EXPORT s3export.video = video s3export.key = key s3export.bucket = bucket s3export.save() create_root_vdn_dataset(s3export, server, headers, name, description) task_name = 'push_video_to_vdn_s3' app.send_task(task_name, args=[s3export.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name]) else: raise NotImplementedError servers = VDNServer.objects.all() context = {'video': video, 'servers': servers} if video.vdn_dataset: context['annotations'] = Region.objects.all().filter(video=video, vdn_dataset__isnull=True, region_type=Region.ANNOTATION) else: context['annotations'] = Region.objects.all().filter(video=video, region_type=Region.ANNOTATION) return render(request, 'push.html', context)
def push(request, video_id): video = Video.objects.get(pk=video_id) if request.method == 'POST': push_type = request.POST.get('push_type') server = VDNServer.objects.get(pk=request.POST.get('server_pk')) token = request.POST.get('token_{}'.format(server.pk)) server.last_token = token server.save() server_url = server.url if not server_url.endswith('/'): server_url += '/' headers = {'Authorization': 'Token {}'.format(server.last_token)} if push_type == 'annotation': new_vdn_dataset = create_child_vdn_dataset(video, server, headers) for key in request.POST: if key.startswith('annotation_') and request.POST[key]: annotation = Region.objects.get(pk=int(key.split('annotation_')[1])) data = { 'label': annotation.label, 'metadata_text': annotation.metadata_text, 'x': annotation.x, 'y': annotation.y, 'w': annotation.w, 'h': annotation.h, 'full_frame': annotation.full_frame, 'parent_frame_index': annotation.parent_frame_index, 'dataset_id': int(new_vdn_dataset.url.split('/')[-2]), } r = requests.post("{}/api/annotations/".format(server_url), data=data, headers=headers) if r.status_code == 201: annotation.vdn_dataset = new_vdn_dataset annotation.save() else: raise ValueError elif push_type == 'dataset': key = request.POST.get('key') region = request.POST.get('region') bucket = request.POST.get('bucket') name = request.POST.get('name') description = request.POST.get('description') vdn = create_root_vdn_dataset(region, bucket, key, server, headers, name, description) video.vdn_dataset = vdn spec = { 'process_type':DVAPQL.PROCESS, 'tasks':[ { 'operation':'push_video_to_vdn_s3', 'arumgents': {'key':key, 'bucket':bucket, 'region':region} } ] } p = DVAPQLProcess() p.create_from_json(spec,request.user) p.launch() else: raise NotImplementedError servers = VDNServer.objects.all() context = {'video': video, 'servers': servers} if video.vdn_dataset: context['annotations'] = Region.objects.all().filter(video=video, vdn_dataset__isnull=True, region_type=Region.ANNOTATION) else: context['annotations'] = Region.objects.all().filter(video=video, region_type=Region.ANNOTATION) return render(request, 'push.html', context)