More data in CSV file

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-03-26 23:03:11 +01:00
parent 4ea93d3426
commit a865361117
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 30 additions and 8 deletions

View File

@ -598,7 +598,7 @@ class TournamentPaymentsView(VolunteerMixin, SingleTableMixin, DetailView):
class TournamentExportCSVView(VolunteerMixin, DetailView): class TournamentExportCSVView(VolunteerMixin, DetailView):
""" """
Export team information in a CSV file. Export all team informations in a CSV file.
""" """
model = Tournament model = Tournament
@ -609,24 +609,46 @@ class TournamentExportCSVView(VolunteerMixin, DetailView):
content_type='text/csv', content_type='text/csv',
headers={'Content-Disposition': f'attachment; filename="Tournoi de {tournament.name}.csv"'}, headers={'Content-Disposition': f'attachment; filename="Tournoi de {tournament.name}.csv"'},
) )
writer = csv.DictWriter(resp, ('Tournoi', 'Équipe', 'Trigramme', 'Nom', 'Prénom', 'Email', writer = csv.DictWriter(resp, ('Tournoi', 'Équipe', 'Trigramme', 'Sélectionnée',
'Genre', 'Date de naissance')) '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() 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\ for registration in participation.team.participants\
.order_by('coachregistration', 'user__last_name').all(): .order_by('coachregistration', 'user__last_name').all():
writer.writerow({ writer.writerow({
'Tournoi': tournament.name, 'Tournoi': tournament.name,
'Équipe': participation.team.name, 'Équipe': participation.team.name,
'Trigramme': participation.team.trigram, '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, 'Nom': registration.user.last_name,
'Prénom': registration.user.first_name, 'Prénom': registration.user.first_name,
'Email': registration.user.email, 'Email': registration.user.email,
'Genre': registration.get_gender_display() if isinstance(registration, StudentRegistration) 'Type': registration.type.capitalize(),
else 'Encadrant⋅e', 'Genre': registration.get_gender_display() if registration.is_student else '',
'Date de naissance': registration.birth_date if isinstance(registration, StudentRegistration) 'Date de naissance': registration.birth_date if registration.is_student else '',
else 'Encadrant⋅e', '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 return resp