Update problem.py

Fixed, if you follow the docs of DMOJ to setup nginx and supervisor, Pdf view won't work
This commit is contained in:
Tran Trong Nghia 2022-12-20 21:14:19 +07:00 committed by GitHub
parent 36007e86ed
commit 465dd08043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -431,11 +431,11 @@ class ProblemPdfDescriptionView(ProblemMixin, SingleObjectMixin, View):
if not problem.pdf_description:
raise Http404()
response = HttpResponse()
if request.META.get("SERVER_SOFTWARE", "").startswith("nginx/"):
response["X-Accel-Redirect"] = problem.pdf_description.path
else:
with open(problem.pdf_description.path, "rb") as f:
response.content = f.read()
#if request.META.get("SERVER_SOFTWARE", "").startswith("nginx/"):
# response["X-Accel-Redirect"] = problem.pdf_description.path
#else:
with open(problem.pdf_description.path, "rb") as f:
response.content = f.read()
response["Content-Type"] = "application/pdf"
response["Content-Disposition"] = "inline; filename=%s.pdf" % (problem.code,)