From 7decc18ad50ec8129252b953bea47d60f3ad9bc6 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 17 Jan 2021 17:28:59 +0100 Subject: [PATCH] Add other authorizations in the team authorizations --- apps/participation/views.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/participation/views.py b/apps/participation/views.py index 63386b9..5e092b5 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -18,7 +18,7 @@ from django.views.generic import CreateView, DetailView, FormView, RedirectView, from django.views.generic.edit import FormMixin, ProcessFormView from django_tables2 import SingleTableView from magic import Magic -from registration.models import AdminRegistration +from registration.models import AdminRegistration, StudentRegistration from tfjm.lists import get_sympa_client from tfjm.matrix import Matrix from tfjm.views import AdminMixin, VolunteerMixin @@ -315,12 +315,26 @@ class TeamAuthorizationsView(LoginRequiredMixin, DetailView): team = self.get_object() output = BytesIO() zf = ZipFile(output, "w") - for student in team.participants.all(): + for participant in team.participants.all(): magic = Magic(mime=True) - mime_type = magic.from_file("media/" + student.photo_authorization.name) - ext = mime_type.split("/")[1].replace("jpeg", "jpg") - zf.write("media/" + student.photo_authorization.name, - _("Photo authorization of {student}.{ext}").format(student=str(student), ext=ext)) + if participant.photo_authorization: + mime_type = magic.from_file("media/" + participant.photo_authorization.name) + ext = mime_type.split("/")[1].replace("jpeg", "jpg") + zf.write("media/" + participant.photo_authorization.name, + _("Photo authorization of {participant}.{ext}").format(participant=str(participant), ext=ext)) + + if isinstance(participant, StudentRegistration) and participant.parental_authorization: + mime_type = magic.from_file("media/" + participant.parental_authorization.name) + ext = mime_type.split("/")[1].replace("jpeg", "jpg") + zf.write("media/" + participant.parental_authorization.name, + _("Parental authorization of {participant}.{ext}") + .format(participant=str(participant), ext=ext)) + + if participant.health_sheet: + mime_type = magic.from_file("media/" + participant.health_sheet.name) + ext = mime_type.split("/")[1].replace("jpeg", "jpg") + zf.write("media/" + participant.health_sheet.name, + _("Health sheet of {participant}.{ext}").format(participant=str(participant), ext=ext)) zf.close() response = HttpResponse(content_type="application/zip") response["Content-Disposition"] = "attachment; filename=\"{filename}\"" \