# Copyright (C) 2021 by Animath # SPDX-License-Identifier: GPL-3.0-or-later from django.conf import settings from django.core.management import BaseCommand from django.utils.formats import date_format from django.utils.translation import activate from participation.models import Tournament class Command(BaseCommand): def handle(self, *args, **kwargs): activate(settings.PREFERRED_LANGUAGE_CODE) tournaments = Tournament.objects.order_by('-date_start', 'name') for tournament in tournaments: self.handle_tournament(tournament) self.w("") self.w("") def w(self, msg, prefix="", suffix=""): self.stdout.write(f"{prefix}{msg}{suffix}") 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"

{name}

") self.w("") self.w("") self.w("") if tournament.final: 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'ETEAM.

") 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("
") self.w("") self.w("") self.w("") self.w(" ") self.w(" ") self.w(" ") self.w(" ") self.w(" ") self.w("") self.w("") self.w("") for i, (participation, note) in enumerate(notes): self.w("") bold = (not tournament.final and participation.final) or (tournament.final and i < 2) if bold: prefix, suffix = " " else: prefix, suffix = " " self.w(f"{participation.team.name} ({participation.team.trigram})", prefix, suffix) for tournament_round in [1, 2]: pool_note = sum(pool.average(participation) for pool in tournament.pools.filter(participations=participation, round=tournament_round).all()) self.w(f"{pool_note:.01f}", prefix, suffix) self.w(f"{note:.01f}", prefix, suffix) self.w(participation.mention_final if tournament.final else participation.mention, prefix, suffix) self.w("") self.w("") self.w("
ÉquipeScore Tour 1Score Tour 2TotalPrix
", "", "
") self.w("
") self.w("")