# Copyright (C) 2021 by Animath # SPDX-License-Identifier: GPL-3.0-or-later from django.core.management import BaseCommand from django.utils.formats import date_format from django.utils.translation import activate from .models import Tournament class Command(BaseCommand): def handle(self, *args, **kwargs): activate('fr') tournaments = Tournament.objects.order_by('-date_start', 'name') for tournament in tournaments: self.handle_tournament(tournament) self.w("") self.w("") def w(self, msg): self.stdout.write(msg) def handle_tournament(self, tournament): name = tournament.name date_start = date_format(tournament.date_start, "DATE_FORMAT") date_end = date_format(tournament.date_end, "DATE_FORMAT") notes = dict() for participation in tournament.participations.filter(valid=True).all(): note = sum(pool.average(participation) for pool in tournament.pools.filter(participations=participation).all()) notes[participation] = note notes = sorted(notes.items(), key=lambda x: x[1], reverse=True) self.w("") self.w(f"
La finale a eu lieu le weekend du {date_start} au {date_end} et a été remporté par l'équipe " f"{notes[0][0].team.name} suivie de l'équipe {notes[1][0].team.name}. " f"Les deux premières équipes sont sélectionnées pour représenter la France lors de l'ITYM.
") else: self.w(f"Le tournoi de {name} a eu lieu le weekend du {date_start} au {date_end} et a été remporté par " f"l'équipe {notes[0][0].team.name}.
") self.w("") self.w("") self.w("") self.w("") self.w("| Équipe") self.w("\t | Score Tour 1") self.w("\t | Score Tour 2") self.w("\t | Total") self.w("\t | Prix") self.w(" | |||
|---|---|---|---|---|---|---|---|
| {participation.team.name} ({participation.team.trigram})") else: self.w(f"\t | {participation.team.name} ({participation.team.trigram})") for pool in tournament.pools.filter(participations=participation).all(): pool_note = pool.average(participation) self.w(f"\t | {pool_note:.01f}") self.w(f"\t | {note:.01f}") if i == 0: self.w("\t | 1er prix") elif i < (5 if tournament.final else 3): self.w(f"\t | {i + 1}ème prix") elif i < 2 * len(notes) / 3: self.w("\t | Mention très honorable") else: self.w("\t | Mention honorable") self.w(" |