data_export_14.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. def report_support_upload(request):
  2. form = SupportUploadForm(request.POST)
  3. # check for existing support upload
  4. data = {"created": False}
  5. account = models.RemoteAccount.objects.get(remote_resource="support.iontorrent")
  6. if not account.has_access():
  7. data["error"] = "invalid_auth"
  8. if not form.is_valid():
  9. data["error"] = "invalid_form"
  10. data["form_errors"] = form.errors
  11. if "error" not in data:
  12. result_pk = form.cleaned_data["result"]
  13. support_upload = (
  14. models.SupportUpload.objects.filter(result=result_pk)
  15. .order_by("-id")
  16. .first()
  17. )
  18. if not support_upload:
  19. data["created"] = True
  20. support_upload = models.SupportUpload(
  21. account=account,
  22. result_id=result_pk,
  23. user=request.user,
  24. local_status="Preparing",
  25. contact_email=form.cleaned_data["contact_email"],
  26. description=form.cleaned_data["description"],
  27. )
  28. support_upload.save()
  29. async_result = AsyncResult(support_upload.celery_task_id)
  30. if (
  31. not support_upload.celery_task_id
  32. or async_result.status in celery.states.READY_STATES
  33. ):
  34. if not support_upload.file:
  35. monitor = models.FileMonitor()
  36. monitor.save()
  37. support_upload.file = monitor
  38. support_upload.save()
  39. support_upload.file.status = ("Queued",)
  40. support_upload.file.tags = "support_upload,generate_csa"
  41. support_upload.file.save()
  42. generate = generate_csa.s(result_pk, support_upload.file.pk)
  43. errback = filemonitor_errback.s(support_upload.file.pk)
  44. gen_result = generate.apply_async(link_error=errback)
  45. support_upload.file.celery_task_id = gen_result.task_id
  46. auth_result = check_authentication.delay(support_upload.pk)
  47. upload_result = check_and_upload.apply_async(
  48. (support_upload.pk, auth_result.task_id, gen_result.task_id),
  49. countdown=1,
  50. )
  51. support_upload.celery_task_id = upload_result.task_id
  52. support_upload.save()
  53. resource = SupportUploadResource()
  54. uri = resource.get_resource_uri(support_upload)
  55. data["resource_uri"] = uri
  56. # make CSA
  57. # check auth
  58. # start upload task
  59. # respond with support upload object for JS polling
  60. return HttpResponse(
  61. json.dumps(data, indent=4, sort_keys=True), mimetype="application/json"
  62. )