From 4e3a07d57519d6964b8c946e929a09ba19c13590 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sun, 21 Jun 2020 14:26:46 +0200 Subject: Pdf download, filter on doc type --- client/templates/client/approve_doc_pdf.html | 99 ++++++++++++++++++++++++++++ client/views.py | 15 ++++- 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 client/templates/client/approve_doc_pdf.html (limited to 'client') diff --git a/client/templates/client/approve_doc_pdf.html b/client/templates/client/approve_doc_pdf.html new file mode 100644 index 0000000..4b7df8b --- /dev/null +++ b/client/templates/client/approve_doc_pdf.html @@ -0,0 +1,99 @@ + + + + + + + + +
+

{{doc.code}}

+

{{doc.document_type.name}}

+
+

Con la presente firma approvo il documento con codice {{doc.code}} accettando + tutte le clausole apposte su di esso. + Inoltre comprovo come veritieri e completi tutti i dati apposti sul documento. +

+
+



+



+



+



+
+ + + + + +

Data

Firma

+
+
+ + \ No newline at end of file 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() -- cgit v1.2.1