def report_support_upload(request): form = SupportUploadForm(request.POST) # check for existing support upload data = {"created": False} account = models.RemoteAccount.objects.get(remote_resource="support.iontorrent") if not account.has_access(): data["error"] = "invalid_auth" if not form.is_valid(): data["error"] = "invalid_form" data["form_errors"] = form.errors if "error" not in data: result_pk = form.cleaned_data["result"] support_upload = ( models.SupportUpload.objects.filter(result=result_pk) .order_by("-id") .first() ) if not support_upload: data["created"] = True support_upload = models.SupportUpload( account=account, result_id=result_pk, user=request.user, local_status="Preparing", contact_email=form.cleaned_data["contact_email"], description=form.cleaned_data["description"], ) support_upload.save() async_result = AsyncResult(support_upload.celery_task_id) if ( not support_upload.celery_task_id or async_result.status in celery.states.READY_STATES ): if not support_upload.file: monitor = models.FileMonitor() monitor.save() support_upload.file = monitor support_upload.save() support_upload.file.status = ("Queued",) support_upload.file.tags = "support_upload,generate_csa" support_upload.file.save() generate = generate_csa.s(result_pk, support_upload.file.pk) errback = filemonitor_errback.s(support_upload.file.pk) gen_result = generate.apply_async(link_error=errback) support_upload.file.celery_task_id = gen_result.task_id auth_result = check_authentication.delay(support_upload.pk) upload_result = check_and_upload.apply_async( (support_upload.pk, auth_result.task_id, gen_result.task_id), countdown=1, ) support_upload.celery_task_id = upload_result.task_id support_upload.save() resource = SupportUploadResource() uri = resource.get_resource_uri(support_upload) data["resource_uri"] = uri # make CSA # check auth # start upload task # respond with support upload object for JS polling return HttpResponse( json.dumps(data, indent=4, sort_keys=True), mimetype="application/json" )