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 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'server') 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) -- cgit v1.2.1