diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2020-08-29 14:21:01 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2020-08-29 14:21:01 +0200 |
commit | 10e742446d962889e821a31306fc0388961fccb2 (patch) | |
tree | 8ad956ce4043a53291ff4bb0b37e0c9f527107bf /server | |
parent | wait to render pdf for js to load (diff) | |
download | scout-subs-10e742446d962889e821a31306fc0388961fccb2.tar.gz scout-subs-10e742446d962889e821a31306fc0388961fccb2.zip |
different response for pdf downloads
Diffstat (limited to '')
-rw-r--r-- | server/views.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/server/views.py b/server/views.py index b5e0493..15fb7b1 100644 --- a/server/views.py +++ b/server/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render from client.models import UserCode, Keys, DocumentType, Document, KeyVal from django.contrib.auth.models import Group, Permission, User from django.db.models import Q -from django.http import HttpResponseRedirect, FileResponse +from django.http import HttpResponseRedirect, FileResponse, HttpResponse from django.db.models.deletion import ProtectedError from django.template.loader import get_template from django.conf import settings @@ -222,10 +222,11 @@ def ulist(request): html = template.render(context) # render pdf using wkhtmltopdf pdf = pdfkit.from_string(html, False, options={'javascript-delay':'1000'}) - result = BytesIO(pdf) - result.seek(0) - - return FileResponse(result, as_attachment=True, filename=document.user.username+"_"+document.document_type.name+".pdf") + # build response + filename = document.user.username + "_" + document.document_type.name + ".pdf" + response = HttpResponse(pdf, content_type='application/pdf') + response['Content-Disposition'] = 'attachment; filename="' + filename + '"' + return response # deapprove user elif request.POST["action"][0] == 'd': @@ -603,10 +604,11 @@ def doclist(request): 'health': health_file, 'sign_doc_file': sign_doc_file} html = template.render(context) pdf = pdfkit.from_string(html, False, options={'javascript-delay':'1000'}) - result = BytesIO(pdf) - result.seek(0) - - return FileResponse(result, as_attachment=True, filename=document.user.username+"_"+document.document_type.name+".pdf") + # build response + filename = document.user.username + "_" + document.document_type.name + ".pdf" + response = HttpResponse(pdf, content_type='application/pdf') + response['Content-Disposition'] = 'attachment; filename="' + filename + '"' + return response # get selected documents and check if user has permission to view selected = [] |