aboutsummaryrefslogtreecommitdiffstats
path: root/client/views.py
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-06-21 14:26:46 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-06-21 14:26:46 +0200
commit4e3a07d57519d6964b8c946e929a09ba19c13590 (patch)
tree799982e64b4292187aee7b6996fa4c850d8dc3dc /client/views.py
parentDoc, doctypes, users all done (diff)
downloadscout-subs-4e3a07d57519d6964b8c946e929a09ba19c13590.tar.gz
scout-subs-4e3a07d57519d6964b8c946e929a09ba19c13590.zip
Pdf download, filter on doc type
Diffstat (limited to '')
-rw-r--r--client/views.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/client/views.py b/client/views.py
index b610962..b16e64a 100644
--- a/client/views.py
+++ b/client/views.py
@@ -2,10 +2,14 @@ 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
+from django.http import HttpResponseRedirect, FileResponse
from django.shortcuts import render
+from xhtml2pdf import pisa
+from django.template.loader import get_template
+from io import BytesIO
+
# Create your views here.
@@ -27,7 +31,14 @@ def index(request):
if request.method == "POST":
document = Document.objects.get(id=request.POST["action"][1:])
if request.POST["action"][0] == 'f':
- pass
+ template = get_template('client/approve_doc_pdf.html')
+ context = {'doc': document}
+ html = template.render(context)
+ result = BytesIO()
+ pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
+
+ result.seek(0)
+ return FileResponse(result, as_attachment=True, filename=document.document_type.name+".pdf")
elif request.POST["action"][0] == 'a':
document.status = "ok"
document.save()