Commit 29110a77 authored by Filip Štamcar's avatar Filip Štamcar
Browse files

Fix not storing files

No related merge requests found
Pipeline #9518 failed with stages
in 1 minute and 6 seconds
Showing with 7 additions and 4 deletions
+7 -4
......@@ -6,7 +6,7 @@ import tempfile
from django.conf import settings
from django.core.files import File
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseServerError
from django.http import FileResponse, HttpResponse, HttpResponseBadRequest, HttpResponseServerError
from drf_spectacular.utils import extend_schema
from rest_framework import parsers, viewsets
from rest_framework.decorators import action
......@@ -62,14 +62,17 @@ class LatexViewSet(viewsets.GenericViewSet):
logger.warning(error, exc_info=error)
return HttpResponseBadRequest("Failed to render uploaded file")
# Get the rendered PDF file
output = open(os.path.join(directory, "report.pdf"), "rb")
filename = f"report-{now.strftime('%Y-%m-%d-%H-%M-%S')}.pdf"
# Store result in database
if settings.RENDERER_STORE_FILES:
filename = f"report-{now.strftime('%Y-%m-%d-%H-%M-%S')}.pdf"
document.output.save(filename, File(open(os.path.join(directory, "report.pdf"), "rb")))
document.output.save(filename, File(output))
document.save()
# Return the rendered PDF file
response = HttpResponse(document.output, content_type="application/pdf")
response = FileResponse(output, content_type="application/pdf")
response["Content-Disposition"] = f'attachment; filename="{filename}"'
return response
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment