예제 #1
0
def create_legends_ladders(curr_round, games):
    """
    Create the Legends ladder for each club for round
    """
    ladders = curr_round.legends_ladders()
    round_ladders = []
    for game in curr_round.games.all():
        for club in (game.legends_away, game.legends_home):
            ladder = ladders[club]
            # Clear the existing ladders since we don't know which games are
            # already included
            ladder.clear()

            # Update the ladder contents
            ladder.update_columns(game)
            ladder.finalise()
            round_ladders.append(ladder)

    # If the round has byes we need to copy the previous round's ladder for the
    # affected clubs
    for bye in curr_round.byes.all():
        try:
            ladder = ladders[bye.club]
        except KeyError:
            ladder = LegendsLadder(round=curr_round, club=bye.club)

        # Clear the existing ladders since we don't know which games are
        # already included
        ladder.clear()

        # Update the ladder contents - just finalise since there's no game info
        # to worry about
        ladder.finalise()
        round_ladders.append(ladder)

    sorted_ladder = curr_round.sort_ladder(round_ladders, reverse=False)
    for index, row in enumerate(sorted_ladder):
        row.position = index + 1
        row.save()