MCPcopy
hub / github.com/WebODM/WebODM / create

Method create

app/api/tasks.py:373–422  ·  view source on GitHub ↗
(self, request, project_pk=None)

Source from the content-addressed store, hash-verified

371 return Response({'error': _("Cannot duplicate task")}, status=status.HTTP_200_OK)
372
373 def create(self, request, project_pk=None):
374 project = get_and_check_project(request, project_pk, ('change_project', ))
375
376 # Check if user has permissions to set processing node
377 check_processing_node_perms(request)
378
379 # Check if an alignment field is set to a valid task
380 # this means a user wants to align this task with another
381 align_to = request.data.get('align_to')
382 align_task = None
383 if align_to is not None and align_to != "auto" and align_to != "":
384 try:
385 align_task = models.Task.objects.select_related('project').get(pk=align_to)
386 check_project_perms(request, align_task.project, ('view_project', ))
387 except ObjectDoesNotExist:
388 raise exceptions.ValidationError(detail=_("Cannot create task, alignment task is not valid"))
389
390 # If this is a partial task, we're going to upload images later
391 # for now we just create a placeholder task.
392 if request.data.get('partial'):
393 task = models.Task.objects.create(project=project,
394 pending_action=pending_actions.RESIZE if 'resize_to' in request.data else None)
395 if align_task is not None:
396 task.set_alignment_file_from(align_task)
397
398 serializer = TaskSerializer(task, data=request.data, partial=True)
399 serializer.is_valid(raise_exception=True)
400 serializer.save()
401 else:
402 files = flatten_files(request.FILES)
403
404 if len(files) <= 1:
405 raise exceptions.ValidationError(detail=_("Cannot create task, you need at least 2 images"))
406
407 with transaction.atomic():
408 task = models.Task.objects.create(project=project,
409 pending_action=pending_actions.RESIZE if 'resize_to' in request.data else None)
410 if align_task is not None:
411 task.set_alignment_file_from(align_task)
412 task.handle_images_upload(files)
413 task.images_count = len(task.scan_images())
414
415 # Update other parameters such as processing node, task name, etc.
416 serializer = TaskSerializer(task, data=request.data, partial=True)
417 serializer.is_valid(raise_exception=True)
418 serializer.save()
419
420 worker_tasks.process_task.delay(task.id)
421
422 return Response(serializer.data, status=status.HTTP_201_CREATED)
423
424
425 def update(self, request, pk=None, project_pk=None, partial=False):

Callers 15

ObjDetect.jsxFile · 0.45
Contours.jsxFile · 0.45
gFunction · 0.45
Chart.min.jsFile · 0.45
heFunction · 0.45
CiFunction · 0.45
constructorMethod · 0.45
registerMethod · 0.45
cnFunction · 0.45
getOptionScopesMethod · 0.45
sync_processing_nodeMethod · 0.45

Calls 11

get_and_check_projectFunction · 0.85
check_project_permsFunction · 0.85
TaskSerializerClass · 0.85
flatten_filesFunction · 0.85
handle_images_uploadMethod · 0.80
scan_imagesMethod · 0.80
_Function · 0.50
getMethod · 0.45
saveMethod · 0.45

Tested by 15

test_panorama_tilesMethod · 0.36
test_projectMethod · 0.36
test_basemapMethod · 0.36
test_core_pluginsMethod · 0.36
test_quotaMethod · 0.36
test_quotaMethod · 0.36
test_project_cleanupMethod · 0.36
test_exportsMethod · 0.36
test_flightpathMethod · 0.36
test_tagsMethod · 0.36