aboutsummaryrefslogtreecommitdiffstats
path: root/client/views.py
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-06-22 23:03:32 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-06-22 23:03:32 +0200
commit987a6d3c553dbfdfc37bfc9f0f656d107c74f85e (patch)
treef0a22330f85a4de171d144645e11bf647e935abf /client/views.py
parentChips filter, date filter, fix buttons with text (diff)
downloadscout-subs-987a6d3c553dbfdfc37bfc9f0f656d107c74f85e.tar.gz
scout-subs-987a6d3c553dbfdfc37bfc9f0f656d107c74f85e.zip
Download docs, better preview
Diffstat (limited to 'client/views.py')
-rw-r--r--client/views.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/client/views.py b/client/views.py
index b16e64a..b43a3c9 100644
--- a/client/views.py
+++ b/client/views.py
@@ -6,9 +6,9 @@ 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
+import pdfkit
# Create your views here.
@@ -30,15 +30,19 @@ def index(request):
if request.method == "POST":
document = Document.objects.get(id=request.POST["action"][1:])
+
+ if document.user != request.user:
+ return
+
if request.POST["action"][0] == 'f':
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)
-
+ pdf = pdfkit.from_string(html, False)
+ result = BytesIO(pdf)
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()
@@ -68,11 +72,13 @@ def index(request):
personal = None
medical = None
if i.document_type.personal_data:
- personal = i.personal_data.__dict__.values()
+ personal = i.personal_data
if i.document_type.medical_data:
- medical = i.medical_data.__dict__.values()
+ medical = i.medical_data
+
+ doc_group = i.user.groups.values_list('name', flat=True)[0]
- out.append([i, KeyVal.objects.filter(container=i), personal, medical])
+ out.append([i, KeyVal.objects.filter(container=i), personal, medical, doc_group])
context = {
"docs": out,
"empty": len(out) == 0,