From b053a47a19d537ad5e82b3bc3412cee04ad811a2 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Mon, 28 Oct 2024 21:33:58 +0100 Subject: [PATCH] Add export photo authorizations script Signed-off-by: Emmy D'Anello --- .../management/commands/export_solutions.py | 3 +- .../commands/export_photo_authorizations.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 registration/management/commands/export_photo_authorizations.py diff --git a/participation/management/commands/export_solutions.py b/participation/management/commands/export_solutions.py index a97c315..ca3c7ca 100644 --- a/participation/management/commands/export_solutions.py +++ b/participation/management/commands/export_solutions.py @@ -11,10 +11,9 @@ from participation.models import Solution, Tournament class Command(BaseCommand): def handle(self, *args, **kwargs): - activate(settings.PROBLEMS) - base_dir = Path(__file__).parent.parent.parent.parent base_dir /= "output" + base_dir /= "solutions" if not base_dir.is_dir(): base_dir.mkdir() base_dir /= "Par équipe" diff --git a/registration/management/commands/export_photo_authorizations.py b/registration/management/commands/export_photo_authorizations.py new file mode 100644 index 0000000..20cdb8e --- /dev/null +++ b/registration/management/commands/export_photo_authorizations.py @@ -0,0 +1,35 @@ +# Copyright (C) 2024 by Animath +# SPDX-License-Identifier: GPL-3.0-or-later + +from pathlib import Path + +from django.core.management import BaseCommand +from participation.models import Team + + +class Command(BaseCommand): + help = """Cette commande permet d'exporter dans le dossier output/photo_authorizations l'ensemble des + autorisations de droit à l'image des participant⋅es, triées par équipe, incluant aussi celles de la finale.""" + + def handle(self, *args, **kwargs): + base_dir = Path(__file__).parent.parent.parent.parent + base_dir /= "output" + base_dir / "photo_authorizations" + if not base_dir.is_dir(): + base_dir.mkdir() + + for team in Team.objects.filter(participation__valid=True).all(): + team_dir = base_dir / f"{team.trigram} - {team.name}" + if not team_dir.is_dir(): + team_dir.mkdir() + + for participant in team.participants.all(): + if participant.photo_authorization: + with participant.photo_authorization.file as file_input: + with open(team_dir / f"{participant}.pdf", 'wb') as file_output: + file_output.write(file_input.read()) + + if participant.photo_authorization_final: + with participant.photo_authorization.file as file_input: + with open(team_dir / f"{participant} (finale).pdf", 'wb') as file_output: + file_output.write(file_input.read())