def export_upload_report(request): try: report_pk = int(request.POST.get("report")) except ValueError: raise Http404("'{0}' is not a valid report ID".format(report_pk)) path = request.POST.get("file_path") report = get_object_or_404(models.Results, pk=report_pk) root = report.get_report_dir() full_path = os.path.join(root, path) if not os.path.exists(full_path): raise Http404( "'{0}' does not exist as a file in report {1}".format(path, report_pk) ) tag = "report/{0}/".format(report_pk) monitor = models.FileMonitor( local_dir=os.path.dirname(full_path), name=os.path.basename(full_path), tags="upload," + tag, status="Queued", ) monitor.save() result = export_upload_file.delay(monitor.id) monitor.celery_task_id = result.task_id monitor.save() return redirect("list_export_uploads", tag="")