def next_elimination_stage(request, tournament_id, current_code=None): tournament = Tournament.objects.get(pk=tournament_id) if not current_code: tg = TournamentGroup.objects.filter(tournament=tournament)[0] tg.add_to_elimination() return HttpResponseRedirect(reverse('view-tournament', args=[tournament_id])) new_code = EliminationStatus if tournament.has_double_elimination: tes = list(TournamentElimination.objects.filter(game__tournament=tournament, status__code__startswith=current_code)) while tes: first_game = tes.pop(0).game second_game = tes.pop(0).game if list(current_code)[0] == "W": te = TournamentElimination.objects.get_or_create(game__tournament=tournament, status=list(current_code)[0] + str(int(list(current_code)[1]) + 1)) game = Game(home_team=first_game.loser(), away_team=second_game.loser(), tournament=tournament) game.save() te = TournamentElimination(game=game, status='L' + list(current_code)[1]) te.save() else: tes = list(TournamentElimination.objects.filter(game__tournament=tournament, status__code=current_code)) new_code = EliminationStatus.objects.get(code=(int(current_code) / 2)) while tes: first_game = tes.pop(0).game second_game = tes.pop(0).game game = Game(home_team=first_game.winner(), away_team=second_game.winner(), tournament=tournament) game.save() te = TournamentElimination(game=game, status=new_code) te.save() return HttpResponseRedirect(reverse('view-tournament', args=[tournament_id]))
def next_elimination_stage(request, tournament_id, current_code=None): tournament = Tournament.objects.get(pk=tournament_id) if not current_code: tg = TournamentGroup.objects.filter(tournament=tournament)[0] tg.add_to_elimination() return HttpResponseRedirect(reverse('view-tournament', args=[tournament_id])) tes = list(TournamentElimination.objects.filter(game__tournament=tournament, status__code=current_code)) new_code = EliminationStatus.objects.get(code=(int(current_code) / 2)) while tes: game = Game(home_team=tes.pop(0).game.winner(), away_team=tes.pop().game.winner(), tournament=tournament) game.save() te = TournamentElimination(game=game, status=new_code) te.save() return HttpResponseRedirect(reverse('view-tournament', args=[tournament_id]))