From 9bb7b7bdfaf4130e1fa8e5f9baf93e9f977f7807 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Wed, 29 Jul 2020 23:58:25 +0200 Subject: upload signed documents --- accounts/views.py | 8 +- client/migrations/0026_document_signed_doc.py | 18 ++++ client/models.py | 2 + client/templates/client/index.html | 4 +- server/templates/server/approve_doc.html | 2 +- server/templates/server/doc_list.html | 18 +++- server/templates/server/download_doc.html | 13 ++- server/templates/server/index.html | 8 +- server/templates/server/upload_doc.html | 86 +++++++++++++++++ server/templates/server/user_list.html | 4 +- server/urls.py | 2 + server/views.py | 129 +++++++++++++++++++++++++- 12 files changed, 277 insertions(+), 17 deletions(-) create mode 100644 client/migrations/0026_document_signed_doc.py create mode 100644 server/templates/server/upload_doc.html diff --git a/accounts/views.py b/accounts/views.py index 31786b1..a31d12b 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -123,11 +123,10 @@ def personal(request): if "vac_certificate" in request.FILES: myfile = request.FILES['vac_certificate'] - medic.save() try: im = Image.open(myfile) im_io = BytesIO() - im.save(im_io, 'WEBP', quality=70) + im.save(im_io, 'WEBP', quality=50) medic.vac_certificate.save(request.user.username+"_"+myfile.name, im_io) medic.save() except UnidentifiedImageError: @@ -139,7 +138,7 @@ def personal(request): try: im = Image.open(myfile) im_io = BytesIO() - im.save(im_io, 'WEBP', quality=70) + im.save(im_io, 'WEBP', quality=50) medic.health_care_certificate.save(request.user.username+"_"+myfile.name, im_io) medic.save() except UnidentifiedImageError: @@ -155,6 +154,9 @@ def personal(request): medic.health_care_certificate = None medic.save() + if not error: + return HttpResponseRedirect("") + if len(request.user.groups.values_list('name', flat=True)) == 0: branca_default = "selected" else: diff --git a/client/migrations/0026_document_signed_doc.py b/client/migrations/0026_document_signed_doc.py new file mode 100644 index 0000000..f3b6747 --- /dev/null +++ b/client/migrations/0026_document_signed_doc.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-07-29 19:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0025_documenttype_custom_group'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='signed_doc', + field=models.FileField(default=None, null=True, upload_to='documents/'), + ), + ] diff --git a/client/models.py b/client/models.py index 4d8ae83..7c47cee 100644 --- a/client/models.py +++ b/client/models.py @@ -71,6 +71,8 @@ class Document(models.Model): medical_data = models.ForeignKey( MedicalData, default=None, on_delete=models.PROTECT, null=True) + signed_doc = models.FileField(default=None, upload_to='documents/', null=True) + class Meta: permissions = [ ("approved", "The user is approved") diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 45a7e90..fd8316b 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -310,7 +310,7 @@
- + {% if doc.5 %} {% endif %}
@@ -319,7 +319,7 @@
- + {% if doc.6 %}{% endif %}
diff --git a/server/templates/server/approve_doc.html b/server/templates/server/approve_doc.html index 3657f8f..c4bdca4 100644 --- a/server/templates/server/approve_doc.html +++ b/server/templates/server/approve_doc.html @@ -1,6 +1,6 @@ {% extends 'registration/base.html' %} -{% block title %}Admin - Approva Utente{% endblock %} +{% block title %}Admin - Approva Documento{% endblock %} {% block nav %} Home diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index 3953905..12b64cd 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -86,6 +86,16 @@