aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/views.py8
-rw-r--r--server/views.py20
2 files changed, 16 insertions, 12 deletions
diff --git a/client/views.py b/client/views.py
index b1b8297..57747ee 100644
--- a/client/views.py
+++ b/client/views.py
@@ -49,9 +49,11 @@ def index(request):
context = {'doc': document}
html = template.render(context)
pdf = pdfkit.from_string(html, False)
- result = BytesIO(pdf)
- result.seek(0)
- return FileResponse(result, as_attachment=True, filename=document.document_type.name+".pdf")
+ # build response
+ filename = document.document_type.name + ".pdf"
+ response = HttpResponse(pdf, content_type='application/pdf')
+ response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
+ return response
elif request.POST["action"][0] == 'a':
# sign autosign doc
if document.status == "autosign":
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 = []