1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-23 21:16:36 +02:00

Add button to download all solutions and syntheses in a ZIP file

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2023-05-19 14:44:31 +02:00
parent 9bc0e99d6d
commit 29074c4bfd
5 changed files with 193 additions and 116 deletions

View File

@ -733,6 +733,42 @@ class PoolUpdateTeamsView(VolunteerMixin, UpdateView):
return self.handle_no_permission()
class PoolDownloadView(VolunteerMixin, DetailView):
"""
Download all solutions or syntheses as a ZIP archive.
"""
model = Pool
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return self.handle_no_permission()
if request.user.registration.is_admin or request.user.registration.is_volunteer \
and (self.get_object().tournament in request.user.registration.organized_tournaments.all()
or request.user.registration in self.get_object().juries.all()):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
def get(self, request, *args, **kwargs):
pool = self.get_object()
is_solution = 'solutions' in request.path
output = BytesIO()
zf = ZipFile(output, "w")
for s in (pool.solutions if is_solution else Synthesis.objects.filter(passage__pool=pool).all()):
zf.write("media/" + s.file.name, f"{s}.pdf")
zf.close()
response = HttpResponse(content_type="application/zip")
filename = _("Solutions for pool {pool} of tournament {tournament}.zip") \
if is_solution else _("Syntheses for pool {pool} of tournament {tournament}.zip")
filename = filename.format(pool=pool.get_letter_display() + str(pool.round), tournament=pool.tournament.name)
response["Content-Disposition"] = "attachment; filename=\"{filename}\"" \
.format(filename=filename)
response.write(output.getvalue())
return response
class PoolAddJurysView(VolunteerMixin, FormView, DetailView):
"""
This view lets organizers set jurys for a pool, without multiplying clicks.