aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-08-29 14:51:39 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-08-29 14:51:39 +0200
commit6f067ec9a3d6e3c62c0214cdb1bd18f4d2c43905 (patch)
treef5737da4c8e3c2fff85f1f87897620c2f9c728c3
parentpdf download on mobile (diff)
downloadscout-subs-6f067ec9a3d6e3c62c0214cdb1bd18f4d2c43905.tar.gz
scout-subs-6f067ec9a3d6e3c62c0214cdb1bd18f4d2c43905.zip
revert to previous download method
-rw-r--r--client/views.py9
-rw-r--r--server/views.py22
2 files changed, 11 insertions, 20 deletions
diff --git a/client/views.py b/client/views.py
index cb595e8..11ff367 100644
--- a/client/views.py
+++ b/client/views.py
@@ -49,12 +49,9 @@ def index(request):
context = {'doc': document}
html = template.render(context)
pdf = pdfkit.from_string(html, False)
- # build response
- filename = document.document_type.name + ".pdf"
- response = HttpResponse(pdf, content_type='application/pdf')
- response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
- response['Content-Length'] = len(pdf)
- return response
+ result = BytesIO(pdf)
+ result.seek(0)
+ return FileResponse(result, filename=document.document_type.name+".pdf")
elif request.POST["action"][0] == 'a':
# sign autosign doc
if document.status == "autosign":
diff --git a/server/views.py b/server/views.py
index 093b902..2f601e6 100644
--- a/server/views.py
+++ b/server/views.py
@@ -221,13 +221,10 @@ def ulist(request):
# render context
html = template.render(context)
# render pdf using wkhtmltopdf
- pdf = pdfkit.from_string(html, False, options={'javascript-delay':'1000', 'no-stop-slow-scripts':False})
- # build response
- filename = document.user.username + "_" + document.document_type.name + ".pdf"
- response = HttpResponse(pdf, content_type='application/pdf')
- response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
- response['Content-Length'] = len(pdf)
- return response
+ pdf = pdfkit.from_string(html, False, options={'javascript-delay':'5000', 'no-stop-slow-scripts':False})
+ result = BytesIO(pdf)
+ result.seek(0)
+ return FileResponse(result, filename=document.user.username+"_"+document.document_type.name+".pdf")
# deapprove user
elif request.POST["action"][0] == 'd':
@@ -604,13 +601,10 @@ def doclist(request):
context = {'doc': doc, 'vac': vac_file,
'health': health_file, 'sign_doc_file': sign_doc_file}
html = template.render(context)
- pdf = pdfkit.from_string(html, False, options={'javascript-delay':'1000', 'no-stop-slow-scripts':False})
- # build response
- filename = document.user.username + "_" + document.document_type.name + ".pdf"
- response = HttpResponse(pdf, content_type='application/pdf')
- response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
- response['Content-Length'] = len(pdf)
- return response
+ pdf = pdfkit.from_string(html, False, options={'javascript-delay':'5000', 'no-stop-slow-scripts':False})
+ result = BytesIO(pdf)
+ result.seek(0)
+ return FileResponse(result, filename=document.user.username+"_"+document.document_type.name+".pdf")
# get selected documents and check if user has permission to view
selected = []