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 --- accounts/views.py | 8 +- client/templates/client/approve_doc_pdf.html | 99 +++++++++++++++++++++ client/views.py | 15 +++- server/templates/server/doc_list.html | 123 ++++++++++++++++++++++++++- server/templates/server/doc_type.html | 94 +++++++++++++++++++- server/templates/server/index.html | 3 + server/views.py | 106 +++++++++++++++++++---- templates/registration/base_custom.html | 2 +- 8 files changed, 422 insertions(+), 28 deletions(-) create mode 100644 client/templates/client/approve_doc_pdf.html diff --git a/accounts/views.py b/accounts/views.py index 36f59cd..804a841 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -77,10 +77,16 @@ def personal(request): else: parent_group = request.user.groups.values_list('name', flat=True)[ 0] - if parent_group == "muta": + if parent_group == "colonia": + branca_castorini = "selected" + elif parent_group == "muta": branca_lupetti = "selected" elif parent_group == "reparto": branca_esploratori = "selected" + elif parent_group == "posto": + branca_pionieri = "selected" + elif parent_group == "clan": + branca_rover = "selected" else: branca_default = "selected" 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() diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index 0b3d800..730837c 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -3,16 +3,13 @@ {% block title %}Admin - Documenti{% endblock %} {% block nav %} -