From a865361117d109c03df461962f0edb17c43c4369 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Tue, 26 Mar 2024 23:03:11 +0100 Subject: [PATCH] More data in CSV file Signed-off-by: Emmy D'Anello --- participation/views.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/participation/views.py b/participation/views.py index 95d32f8..287c9c0 100644 --- a/participation/views.py +++ b/participation/views.py @@ -598,7 +598,7 @@ class TournamentPaymentsView(VolunteerMixin, SingleTableMixin, DetailView): class TournamentExportCSVView(VolunteerMixin, DetailView): """ - Export team information in a CSV file. + Export all team informations in a CSV file. """ model = Tournament @@ -609,24 +609,46 @@ class TournamentExportCSVView(VolunteerMixin, DetailView): content_type='text/csv', headers={'Content-Disposition': f'attachment; filename="Tournoi de {tournament.name}.csv"'}, ) - writer = csv.DictWriter(resp, ('Tournoi', 'Équipe', 'Trigramme', 'Nom', 'Prénom', 'Email', - 'Genre', 'Date de naissance')) + writer = csv.DictWriter(resp, ('Tournoi', 'Équipe', 'Trigramme', 'Sélectionnée', + 'Nom', 'Prénom', 'Email', 'Type', 'Genre', 'Date de naissance', + 'Adresse', 'Code postal', 'Ville', 'Téléphone', + 'Classe', 'Établissement', + 'Nom responsable légal⋅e', 'Téléphone responsable légal⋅e', + 'Email responsable légal⋅e', + 'Problèmes de santé', 'Contraintes de logement')) writer.writeheader() - for participation in tournament.participations.filter(valid=True).order_by('team__trigram').all(): + participations = tournament.participations + if 'all' not in request.GET: + participations = participations.filter(valid=True) + for participation in participations.order_by('-valid', 'team__trigram').all(): for registration in participation.team.participants\ .order_by('coachregistration', 'user__last_name').all(): writer.writerow({ 'Tournoi': tournament.name, 'Équipe': participation.team.name, 'Trigramme': participation.team.trigram, + 'Sélectionnée': ("oui" if participation.valid else + "en attente" if participation.valid is False else "non"), 'Nom': registration.user.last_name, 'Prénom': registration.user.first_name, 'Email': registration.user.email, - 'Genre': registration.get_gender_display() if isinstance(registration, StudentRegistration) - else 'Encadrant⋅e', - 'Date de naissance': registration.birth_date if isinstance(registration, StudentRegistration) - else 'Encadrant⋅e', + 'Type': registration.type.capitalize(), + 'Genre': registration.get_gender_display() if registration.is_student else '', + 'Date de naissance': registration.birth_date if registration.is_student else '', + 'Adresse': registration.address, + 'Code postal': registration.zip_code, + 'Ville': registration.city, + 'Téléphone': registration.phone_number, + 'Classe': registration.get_student_class_display() if registration.is_student + else registration.last_degree, + 'Établissement': registration.school if registration.is_student + else registration.professional_activity, + 'Nom responsable légal⋅e': registration.responsible_name if registration.is_student else '', + 'Téléphone responsable légal⋅e': registration.responsible_phone if registration.is_student else '', + 'Email responsable légal⋅e': registration.responsible_email if registration.is_student else '', + 'Problèmes de santé': registration.health_issues, + 'Contraintes de logement': registration.housing_constraints, }) return resp