aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-08-29 14:28:27 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-08-29 14:28:27 +0200
commit56e8a0053e35718f634586bdb14f066c65fad104 (patch)
tree12de4fc7ee3fea2ef81cce74a0191c138c54c657
parentdifferent response for pdf downloads (diff)
downloadscout-subs-56e8a0053e35718f634586bdb14f066c65fad104.tar.gz
scout-subs-56e8a0053e35718f634586bdb14f066c65fad104.zip
pdf download on mobile
-rw-r--r--client/views.py3
-rw-r--r--server/views.py6
2 files changed, 6 insertions, 3 deletions
diff --git a/client/views.py b/client/views.py
index 57747ee..cb595e8 100644
--- a/client/views.py
+++ b/client/views.py
@@ -2,7 +2,7 @@ from random import randint
from django.contrib.auth.models import Group, Permission, User
from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData
from django.db.models import Q
-from django.http import HttpResponseRedirect, FileResponse
+from django.http import HttpResponseRedirect, FileResponse, HttpResponse
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
@@ -53,6 +53,7 @@ def index(request):
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
elif request.POST["action"][0] == 'a':
# sign autosign doc
diff --git a/server/views.py b/server/views.py
index 15fb7b1..093b902 100644
--- a/server/views.py
+++ b/server/views.py
@@ -221,11 +221,12 @@ def ulist(request):
# render context
html = template.render(context)
# render pdf using wkhtmltopdf
- pdf = pdfkit.from_string(html, False, options={'javascript-delay':'1000'})
+ 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
# deapprove user
@@ -603,11 +604,12 @@ 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'})
+ 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
# get selected documents and check if user has permission to view