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 --- server/templates/server/doc_list.html | 205 ++++++++++++++++++++--- server/templates/server/download_doc.html | 265 ++++++++++++++++++++++++++++++ server/views.py | 34 +++- 3 files changed, 477 insertions(+), 27 deletions(-) create mode 100644 server/templates/server/download_doc.html (limited to 'server') diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index 8a6be37..961b9ab 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -128,12 +128,19 @@ {{doc.0.user.first_name}} {{doc.0.user.last_name}}
+ {% if doc.0.status == "ok" or doc.0.status == 'archive' %} + file_download Scarica documento +
+
+ {% endif %}
    + {% if doc.0.status == 'ok' or doc.0.status == 'archive' %}
  • - confirmation_numberDEBUG {{doc.0.code}} + confirmation_number{{doc.0.code}}
  • + {% endif %}
  • send{{doc.0.compilation_date}} @@ -145,15 +152,64 @@ personDati personali
    - - - {% for field in doc.2 %} - - - - {% endfor %} - -
    {{field}}
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
  • {% endif %} @@ -163,15 +219,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 %} diff --git a/server/templates/server/download_doc.html b/server/templates/server/download_doc.html new file mode 100644 index 0000000..0f36372 --- /dev/null +++ b/server/templates/server/download_doc.html @@ -0,0 +1,265 @@ +{% extends 'registration/base_custom.html' %} + +{% block title %}Admin - Documenti{% endblock %} + +{% block content %} +
    +
  • +
    + {% if doc.0.status == "wait" %} + timelapse + {% elif doc.0.status == "ok" %} + check + {% elif doc.0.status == "archive" %} + archive + {% elif doc.0.status == "autosign" %} + assignment_turned_in + {% endif %} + {{doc.0.document_type.name}} + {{doc.0.compilation_date}} +
    +
    +
      + {% if doc.0.status == 'ok' or doc.0.status == 'archive' %} +
    • +
      + confirmation_number{{doc.0.code}} +
      +
    • + {% endif %} +
    • +
      + send{{doc.0.compilation_date}} +
      +
    • + {% if doc.0.document_type.personal_data %} +
    • +
      + personDati personali +
      +
      +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      +
      +
    • + {% endif %} + {% if doc.0.document_type.medical_data %} +
    • +
      + healingDati medici +
      +
      +
      +
      +
      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 %} + {% if doc.0.document_type.custom_data %} +
    • +
      + add_circle_outlineDati aggiuntivi +
      +
      + + + {% for key in doc.1 %} + + + + + {% endfor %} + +
      {{key.key}}{{key.value}}
      +
      +
    • + {% endif %} +
    +
    +
  • +
+ +{% endblock %} + +{%block script%} +document.addEventListener('DOMContentLoaded', function() { + var elems = document.querySelectorAll('.collapsible'); + var options = { + accordion: false + } + var instances = M.Collapsible.init(elems, options); + }); +{% endblock %} \ No newline at end of file diff --git a/server/views.py b/server/views.py index 296dae4..fb6af0f 100644 --- a/server/views.py +++ b/server/views.py @@ -2,13 +2,16 @@ from django.shortcuts import render from client.models import UserCode, Keys, DocumentType, Document, KeyVal from django.contrib.auth.models import Group, Permission, User from django.db.models import Q -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, FileResponse from django.db.models.deletion import ProtectedError +from django.template.loader import get_template import dateparser from datetime import datetime from datetime import timedelta import pytz +import pdfkit +from io import BytesIO # Create your views here. @@ -364,6 +367,9 @@ def doccreate(request): def doclist(request): context = {} if request.user.is_staff: + parent_group = request.user.groups.values_list('name', flat=True)[ + 0] + group = Group.objects.get(name=parent_group) zurich = pytz.timezone('Europe/Zurich') error = False error_text = "" @@ -385,6 +391,19 @@ def doclist(request): chips_types = [] if request.method == "POST": + if request.POST["action"][0] == 'f': + document = Document.objects.get(id=request.POST["action"][1:]) + if document.group == group: + template = get_template('server/download_doc.html') + doc = [document, KeyVal.objects.filter(container=document), document.personal_data, document.medical_data, parent_group] + context = {'doc': doc} + html = template.render(context) + pdf = pdfkit.from_string(html, False) + result = BytesIO(pdf) + result.seek(0) + + return FileResponse(result, as_attachment=True, filename=document.user.username+"_"+document.document_type.name+".pdf") + selected = [] for i in request.POST.keys(): if i.isdigit(): @@ -430,9 +449,6 @@ def doclist(request): owner = [] types = [] - parent_group = request.user.groups.values_list('name', flat=True)[ - 0] - group = Group.objects.get(name=parent_group) documents = Document.objects.filter(group=group) if not hidden: @@ -474,11 +490,13 @@ def doclist(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 - out.append([i, KeyVal.objects.filter(container=i), personal, medical]) + doc_group = i.user.groups.values_list('name', flat=True)[0] + + out.append([i, KeyVal.objects.filter(container=i), personal, medical, doc_group]) auto_types = DocumentType.objects.filter(Q(group_private=False) | Q(group=group)) users = User.objects.filter(groups__name=parent_group) @@ -499,4 +517,4 @@ def doclist(request): } return render(request, 'server/doc_list.html', context) else: - return render(request, 'client/index.html', context) + return render(request, 'client/index.html', context) \ No newline at end of file -- cgit v1.2.1