data_export_5.py 936 B

12345678910111213141516171819202122232425262728
  1. def export_upload_report(request):
  2. try:
  3. report_pk = int(request.POST.get("report"))
  4. except ValueError:
  5. raise Http404("'{0}' is not a valid report ID".format(report_pk))
  6. path = request.POST.get("file_path")
  7. report = get_object_or_404(models.Results, pk=report_pk)
  8. root = report.get_report_dir()
  9. full_path = os.path.join(root, path)
  10. if not os.path.exists(full_path):
  11. raise Http404(
  12. "'{0}' does not exist as a file in report {1}".format(path, report_pk)
  13. )
  14. tag = "report/{0}/".format(report_pk)
  15. monitor = models.FileMonitor(
  16. local_dir=os.path.dirname(full_path),
  17. name=os.path.basename(full_path),
  18. tags="upload," + tag,
  19. status="Queued",
  20. )
  21. monitor.save()
  22. result = export_upload_file.delay(monitor.id)
  23. monitor.celery_task_id = result.task_id
  24. monitor.save()
  25. return redirect("list_export_uploads", tag="")