diff options
Diffstat (limited to '')
-rw-r--r-- | server/templates/server/data_request.html | 2 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 19 | ||||
-rw-r--r-- | server/views.py | 224 | ||||
-rw-r--r-- | version.txt | 2 |
4 files changed, 244 insertions, 3 deletions
diff --git a/server/templates/server/data_request.html b/server/templates/server/data_request.html index 1db580c..fbbcbc0 100644 --- a/server/templates/server/data_request.html +++ b/server/templates/server/data_request.html @@ -20,6 +20,8 @@ <option value="" disabled selected>Scegli</option> <option value="email_all">Email (tutti gli utenti)</option> <option value="email_non_staff">Email (solo non capi)</option> + <option value="data_user">CSV Dati personali</option> + <option value="data_user_medic">CSV Dati personali + medici</option> </select> <label>Richiesta dati</label> </div> diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index c407239..1ef1433 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -144,7 +144,24 @@ <span class="new badge {{color}}" data-badge-caption="">{{doctype.2}}</span> </div> <div class="collapsible-body"><span> - <a class="waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.0.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a> + <div class="hide-on-med-and-down"> + <a class="waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.0.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a> + <a class="waves-effect waves-light btn {{color}}" onclick="send('d{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a> + {% if doctype.0.medical_data %} + <a class="waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a> + {% endif %} + </div> + <div style="margin-bottom: 0px;" class="hide-on-large-only row"> + <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.0.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a> + <br> + <br> + <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('d{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a> + {% if doctype.0.medical_data %} + <br> + <br> + <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a> + {% endif %} + </div> <br> <br> <ul class="collection"> diff --git a/server/views.py b/server/views.py index a9dfa74..6367c0c 100644 --- a/server/views.py +++ b/server/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from client.models import UserCode, Keys, DocumentType, Document, KeyVal +from client.models import MedicalData, 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, FileResponse, HttpResponse @@ -12,6 +12,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.sessions.backends.db import SessionStore from django import template +import csv import dateparser from datetime import datetime from datetime import timedelta @@ -331,6 +332,10 @@ def doctype(request): if request.POST["action"][0] == 'e': document_type = DocumentType.objects.get(id=request.POST["action"][1:]) + # check if user has permission on the document + if document_type.group.name not in parent_groups: + return + enabled_check = 'checked="checked"' if document_type.enabled else "" sign_check = 'checked="checked"' if not document_type.auto_sign else "" custom_message_check = 'checked="checked"' if document_type.custom_message else "" @@ -349,6 +354,132 @@ def doctype(request): return docedit_wrapper(request, context) + # check if request to download + elif request.POST["action"][0] == 'd': + document_type = DocumentType.objects.get(id=request.POST["action"][1:]) + + # check if user has permission on the document + if document_type.group.name not in parent_groups: + return + + docs = Document.objects.filter(document_type=document_type) + + # get time for filename + current_time = datetime.strftime(datetime.now(), "%H_%M__%d_%m_%y") + + response = HttpResponse() + response['Content-Disposition'] = 'attachment; filename="' + document_type.name.replace(' ', '_') + '_export_' + current_time + '.csv"' + + writer = csv.writer(response) + + # csv header + writer.writerow(["Nome", "Cognome", "Email", "Stato", "Data di compilazione", "Nome dei genitori", "Via", "CAP", "Paese", "Nazionalita", "Data di nascita", "Telefono di casa", "Telefono", "Scuola", "Anno scolastico", "Numero AVS"]) + + for doc in docs: + writer.writerow([ + doc.user.first_name, + doc.user.last_name, + doc.user.email, + doc.status, + doc.compilation_date, + doc.personal_data.parent_name, + doc.personal_data.via, + doc.personal_data.cap, + doc.personal_data.country, + doc.personal_data.nationality, + doc.personal_data.born_date, + doc.personal_data.home_phone, + doc.personal_data.phone, + doc.personal_data.school, + doc.personal_data.year, + doc.personal_data.avs_number + ]) + + return response + + #check if request to download with medic data + elif request.POST["action"][0] == 'm': + document_type = DocumentType.objects.get(id=request.POST["action"][1:]) + + # check if user has permission on the document + if document_type.group.name not in parent_groups: + return + + docs = Document.objects.filter(document_type=document_type) + + # get time for filename + current_time = datetime.strftime(datetime.now(), "%H_%M__%d_%m_%y") + + response = HttpResponse() + response['Content-Disposition'] = 'attachment; filename="' + document_type.name.replace(' ', '_') + '_export_medic_' + current_time + '.csv"' + + writer = csv.writer(response) + + # csv header + writer.writerow(["Nome", "Cognome", "Email", "Stato", "Data di compilazione", "Nome dei genitori", "Via", "CAP", "Paese", "Nazionalita", "Data di nascita", "Telefono di casa", "Telefono", "Scuola", "Anno scolastico", "Numero AVS", "Contatto d'emergenza", "Parentela del contatto", "Telefono d'emergenza", "Cellulare emergenza", "Indirizzo completo emergenza", "Cassa malati", "Ass. Infortuni", "Ass. RC", "Socio REGA", "Nome del medico", "Telefono medico", "Indirizzo medico", "Malattie", "Vacinazioni", "Data antitetanica", "Allergie", "Assume medicamenti", "Medicamenti", "Informazioni particolari", "Informazioni"]) + + for doc in docs: + if doc.medical_data: + writer.writerow([ + doc.user.first_name, + doc.user.last_name, + doc.user.email, + doc.status, + doc.compilation_date, + doc.personal_data.parent_name, + doc.personal_data.via, + doc.personal_data.cap, + doc.personal_data.country, + doc.personal_data.nationality, + doc.personal_data.born_date, + doc.personal_data.home_phone, + doc.personal_data.phone, + doc.personal_data.school, + doc.personal_data.year, + doc.personal_data.avs_number, + doc.medical_data.emer_name, + doc.medical_data.emer_relative, + doc.medical_data.emer_phone, + doc.medical_data.cell_phone, + doc.medical_data.address, + doc.medical_data.health_care, + doc.medical_data.injuries, + doc.medical_data.rc, + doc.medical_data.rega, + doc.medical_data.medic_name, + doc.medical_data.medic_phone, + doc.medical_data.medic_address, + doc.medical_data.sickness, + doc.medical_data.vaccine, + doc.medical_data.tetanus_date, + doc.medical_data.allergy, + doc.medical_data.drugs_bool, + doc.medical_data.drugs, + doc.medical_data.misc_bool, + doc.medical_data.misc + ]) + else: + writer.writerow([ + doc.user.first_name, + doc.user.last_name, + doc.user.email, + doc.status, + doc.compilation_date, + doc.personal_data.parent_name, + doc.personal_data.via, + doc.personal_data.cap, + doc.personal_data.country, + doc.personal_data.nationality, + doc.personal_data.born_date, + doc.personal_data.home_phone, + doc.personal_data.phone, + doc.personal_data.school, + doc.personal_data.year, + doc.personal_data.avs_number, + ]) + + return response + # list all selected types for i in request.POST.keys(): if i.isdigit(): @@ -1168,6 +1299,7 @@ def docpreview(request): def data_request(request): context = {} parent_group = request.user.groups.values_list('name', flat=True)[0] + if request.method == "POST": if request.POST["request"] == "email_all": users = User.objects.filter(groups__name=parent_group) @@ -1183,6 +1315,96 @@ def data_request(request): data += user.email + ", " data = data[:-2] context["data"] = data + elif request.POST["request"] == "data_user": + users = User.objects.filter(groups__name=parent_group) + + # get time for filename + current_time = datetime.strftime(datetime.now(), "%H_%M__%d_%m_%y") + + response = HttpResponse() + response['Content-Disposition'] = 'attachment; filename="data_export_' + current_time + '.csv"' + + writer = csv.writer(response) + + # csv header + writer.writerow(["Nome", "Cognome", "Email", "Nome dei genitori", "Via", "CAP", "Paese", "Nazionalita", "Data di nascita", "Telefono di casa", "Telefono", "Scuola", "Anno scolastico", "Numero AVS"]) + + for user in users: + usercode = UserCode.objects.filter(user=user)[0] + writer.writerow([ + user.first_name, + user.last_name, + user.email, + usercode.parent_name, + usercode.via, + usercode.cap, + usercode.country, + usercode.nationality, + usercode.born_date, + usercode.home_phone, + usercode.phone, + usercode.school, + usercode.year, + usercode.avs_number + ]) + + return response + + elif request.POST["request"] == "data_user_medic": + users = User.objects.filter(groups__name=parent_group) + + # get time for filename + current_time = datetime.strftime(datetime.now(), "%H_%M__%d_%m_%y") + + response = HttpResponse() + response['Content-Disposition'] = 'attachment; filename="data_export_' + current_time + '.csv"' + + writer = csv.writer(response) + + # csv header + writer.writerow(["Nome", "Cognome", "Email", "Nome dei genitori", "Via", "CAP", "Paese", "Nazionalita", "Data di nascita", "Telefono di casa", "Telefono", "Scuola", "Anno scolastico", "Numero AVS", "Contatto d'emergenza", "Parentela del contatto", "Telefono d'emergenza", "Cellulare emergenza", "Indirizzo completo emergenza", "Cassa malati", "Ass. Infortuni", "Ass. RC", "Socio REGA", "Nome del medico", "Telefono medico", "Indirizzo medico", "Malattie", "Vacinazioni", "Data antitetanica", "Allergie", "Assume medicamenti", "Medicamenti", "Informazioni particolari", "Informazioni"]) + + for user in users: + usercode = UserCode.objects.filter(user=user)[0] + medic = usercode.medic + writer.writerow([ + user.first_name, + user.last_name, + user.email, + usercode.parent_name, + usercode.via, + usercode.cap, + usercode.country, + usercode.nationality, + usercode.born_date, + usercode.home_phone, + usercode.phone, + usercode.school, + usercode.year, + usercode.avs_number, + medic.emer_name, + medic.emer_relative, + medic.emer_phone, + medic.cell_phone, + medic.address, + medic.health_care, + medic.injuries, + medic.rc, + medic.rega, + medic.medic_name, + medic.medic_phone, + medic.medic_address, + medic.sickness, + medic.vaccine, + medic.tetanus_date, + medic.allergy, + medic.drugs_bool, + medic.drugs, + medic.misc_bool, + medic.misc + ]) + + return response return render(request, 'server/data_request.html', context) def media_request(request, id=0, t="", flag=""): diff --git a/version.txt b/version.txt index 7655692..766a5d5 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.2 -rev=3 +rev=4 |