From 987a6d3c553dbfdfc37bfc9f0f656d107c74f85e Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Mon, 22 Jun 2020 23:03:32 +0200 Subject: Download docs, better preview --- client/migrations/0023_auto_20200622_1708.py | 24 +++ client/migrations/0024_auto_20200622_1930.py | 23 +++ client/models.py | 2 + client/templates/client/approve.html | 2 +- client/templates/client/doc_create.html | 8 +- client/templates/client/doc_edit.html | 26 +++- client/templates/client/index.html | 218 +++++++++++++++++++++++---- client/views.py | 20 ++- 8 files changed, 278 insertions(+), 45 deletions(-) create mode 100644 client/migrations/0023_auto_20200622_1708.py create mode 100644 client/migrations/0024_auto_20200622_1930.py (limited to 'client') diff --git a/client/migrations/0023_auto_20200622_1708.py b/client/migrations/0023_auto_20200622_1708.py new file mode 100644 index 0000000..458ec6d --- /dev/null +++ b/client/migrations/0023_auto_20200622_1708.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-22 15:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0022_auto_20200620_2316'), + ] + + operations = [ + migrations.AddField( + model_name='medicaldata', + name='health_care_certificate', + field=models.FileField(default=None, upload_to='documents/'), + ), + migrations.AddField( + model_name='medicaldata', + name='vac_certificate', + field=models.FileField(default=None, upload_to='documents/'), + preserve_default=False, + ), + ] diff --git a/client/migrations/0024_auto_20200622_1930.py b/client/migrations/0024_auto_20200622_1930.py new file mode 100644 index 0000000..f721298 --- /dev/null +++ b/client/migrations/0024_auto_20200622_1930.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.7 on 2020-06-22 17:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0023_auto_20200622_1708'), + ] + + operations = [ + migrations.AlterField( + model_name='medicaldata', + name='health_care_certificate', + field=models.FileField(default=None, null=True, upload_to='documents/'), + ), + migrations.AlterField( + model_name='medicaldata', + name='vac_certificate', + field=models.FileField(null=True, upload_to='documents/'), + ), + ] diff --git a/client/models.py b/client/models.py index 78b8df4..105165b 100644 --- a/client/models.py +++ b/client/models.py @@ -51,6 +51,8 @@ class MedicalData(models.Model): drugs = models.CharField(default="", max_length=250) misc_bool = models.BooleanField(default=False) misc = models.CharField(default="", max_length=250) + vac_certificate = models.FileField(upload_to='documents/', null=True) + health_care_certificate = models.FileField(default=None, upload_to='documents/', null=True) class Document(models.Model): diff --git a/client/templates/client/approve.html b/client/templates/client/approve.html index e00aedc..f440fbe 100644 --- a/client/templates/client/approve.html +++ b/client/templates/client/approve.html @@ -1,4 +1,4 @@ -{% extends 'registration/base.html' %} +{% extends 'registration/base_client.html' %} {% block title %}Approva{% endblock %} diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html index a095c04..710ba29 100644 --- a/client/templates/client/doc_create.html +++ b/client/templates/client/doc_create.html @@ -1,4 +1,4 @@ -{% extends 'registration/base.html' %} +{% extends 'registration/base_client.html' %} {% block title %}Crea Documento{% endblock %} @@ -46,7 +46,7 @@ {% if personal_data %}
-
+

Il documento conterrà le informazioni personali, prego verificare che siano corrette e aggiornate @@ -59,7 +59,7 @@ {% if medical_data %}

-
+

Il documento conterrà le informazioni mediche, prego verificare che siano corrette e aggiornate @@ -72,7 +72,7 @@ {% if custom_message %}

-
+

{{custom_message_text}} diff --git a/client/templates/client/doc_edit.html b/client/templates/client/doc_edit.html index 8cd5a98..0048fd5 100644 --- a/client/templates/client/doc_edit.html +++ b/client/templates/client/doc_edit.html @@ -1,4 +1,4 @@ -{% extends 'registration/base.html' %} +{% extends 'registration/base_client.html' %} {% block title %}Modifica documento{% endblock %} @@ -26,21 +26,39 @@ {% if personal_data %}

- Il documento conterrà le informazioni personali, prego verificare che siano corrette e aggiornate +
+
+

+ Il documento conterrà le informazioni personali, prego verificare che siano corrette e aggiornate +

+
+
{% endif %} {% if medical_data %}
- Il documento conterrà le informazioni mediche, prego verificare che siano corrette e aggiornate +
+
+

+ Il documento conterrà le informazioni mediche, prego verificare che siano corrette e aggiornate +

+
+
{% endif %} {% if custom_message %}
- {{custom_message_text}} +
+
+

+ {{custom_message_text}} +

+
+
{% endif %} diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 733f62f..ff12e74 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -1,4 +1,4 @@ -{% extends 'registration/base.html' %} +{% extends 'registration/base_client.html' %} {% block title %}Home{% endblock %} @@ -7,10 +7,10 @@ {% endblock%} {% block content %} -
+
-
Aggiungi un documento
-

Usa questo bottone per creare un nuovo documento

+
Aggiungi un documento
+

Usa questo bottone per creare un nuovo documento

@@ -38,15 +38,15 @@
- - - {% for field in doc.2 %} - - - - {% endfor %} - -
{{field}}
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
{% endif %} @@ -75,15 +124,126 @@ healingDati medici
- - - {% for field in doc.3 %} - - - - {% endfor %} - -
{{field}}
+
+
+
Persona di contatto in caso di necessità
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
Assicurazione
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ È sostenitore REGA   + +
+
+
+
+
Medico di famiglia
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
Scheda medica personale
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ Deve assumere regolarmente medicamenti   + +
+
+ + +
+
+ Informazioni particolari sullo stato di salute: (postumi di operazioni, incidenti, malattie, disturbi fisici)   + +
+
+ + +
{% endif %} @@ -113,7 +273,7 @@ {% endif %} 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, -- cgit v1.2.1