From d11af9ba81ec53953f4503386e22fdaa40b6df04 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Wed, 18 May 2022 17:38:53 +0200 Subject: fix csv download if no personal data --- server/views.py | 29 +++++++++++++++++------------ version.txt | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/server/views.py b/server/views.py index 928eac1..9dbc666 100644 --- a/server/views.py +++ b/server/views.py @@ -374,7 +374,9 @@ def doctype(request): writer = csv.writer(response) # csv header - header = ["Nome", "Cognome", "Email", "Stato", "Data di compilazione", "Nome dei genitori", "Via", "CAP", "Comune", "Nazionalita", "Data di nascita", "Telefono di casa", "Telefono", "Scuola", "Anno scolastico", "Numero AVS"] + header = ["Nome", "Cognome", "Email", "Stato", "Data di compilazione"] + if document_type.personal_data: + header += ["Nome dei genitori", "Via", "CAP", "Comune", "Nazionalita", "Data di nascita", "Telefono di casa", "Telefono", "Scuola", "Anno scolastico", "Numero AVS"] if document_type.custom_data: header += Keys.objects.filter(container=document_type).values_list("key", flat=True) @@ -388,18 +390,21 @@ def doctype(request): 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 ] + if document_type.personal_data: + write_data += [ + 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 + ] if document_type.custom_data: write_data += KeyVal.objects.filter(container=doc).values_list("value", flat=True) diff --git a/version.txt b/version.txt index dfc5e21..d316b6d 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.5 -rev=19 +rev=20 -- cgit v1.2.1