diff --git a/ladder/templates/ladder/ladder/index.html b/ladder/templates/ladder/ladder/index.html index 134f4ce..64291da 100644 --- a/ladder/templates/ladder/ladder/index.html +++ b/ladder/templates/ladder/ladder/index.html @@ -2,73 +2,83 @@ {% load ladder_extras %} {% block container %} - - - - + + + + - + -

{{ ladder }}

-

{{ ladder.season.start_date }} to {{ ladder.season.end_date }}

+

{{ ladder }}

+

{{ ladder.season.start_date }} to {{ ladder.season.end_date }}

Back - - - - {% for i in ladder.league_set.all %} - - {% endfor %} - - - + + + + {% for i in ladder.league_set.all %} + + {% endfor %} + + + - + + {% comment %}Loop over the all players in this ladder{% endcomment %} {% for league in ladder.league_set.all %} + {% comment %}Set the player_counter for the players number{% endcomment %} {% with player_counter=forloop.counter %} + {% comment %}Row data with name, results and scores{% endcomment %} - - {% for opponent in ladder.league_set.all %} - {% with column_counter=forloop.counter %} - {% if column_counter == player_counter %} - - {% else %} - - {% endif %} - {% endwith %} - {% endfor %} + + {% comment %}Loop over all players again to get opponents.{% endcomment %} + {% for opponent in ladder.league_set.all %} + {% comment %}Player cannot play against themselves, fill in box with grey.{% endcomment %} + {% with column_counter=forloop.counter %} + {% if column_counter == player_counter %} + + {% else %} + {% comment %}Score field, with identifier for JS{% endcomment %} + + {% endif %} + {% endwith %} + {% endfor %} @@ -82,9 +92,18 @@

{{ ladder.season.start_date }} to {{ ladder.season.end_date }}

{{ current_season }} Stats

Name {{ forloop.counter }} AverageTotal
Name {{ forloop.counter }} AverageTotal
{{ player_counter }} {{ league.player }} - -
- {% for result in results_dict|getkey:league.player.id %} - {% if league.player == result.player and opponent.player == result.opponent %} - {% if result.inaccurate_flag %} - {{ result.result }} * - - {% else %} - {{ result.result }} - {% endif %} - {% endif %} - {% endfor %} -
-
-
{{ league.player }} + {% comment %}Head to head link{% endcomment %} + + {% comment %}todo: remove these styles.{% endcomment %} +
+ {% comment %}Loop over every result of player{% endcomment %} + {% for result in results_dict|getkey:league.player.id %} + {% comment %}See if it matches opponent and print result.{% endcomment %} + {% if league.player == result.player and opponent.player == result.opponent %} + {% if result.inaccurate_flag %} + {{ result.result }} * + + {% else %} + {{ result.result }} + {% endif %} + {% endif %} + {% endfor %} +
+
+
{{ results_dict|getaverage:league.player.id }} {{ results_dict|gettotal:league.player.id }}
- - - + + + + + + + + + + + +
Total Matches in Division{{ ladder.get_stats.total_matches }}
Total Matches Played{{ ladder.get_stats.total_matches_played|floatformat:"0" }}
Percentage Matches Played{{ ladder.get_stats.perc_matches_played|floatformat:"2" }}%
Total Matches in Division{{ ladder.get_stats.total_matches }}
Total Matches Played{{ ladder.get_stats.total_matches_played|floatformat:"0" }}
Percentage Matches Played{{ ladder.get_stats.perc_matches_played|floatformat:"2" }}%
diff --git a/ladder/views.py b/ladder/views.py index 5787b0e..f529f64 100644 --- a/ladder/views.py +++ b/ladder/views.py @@ -74,11 +74,14 @@ def ladder(request, year, season_round, division_id): ladder_object = get_object_or_404(Ladder, division=division_id, season__start_date__year=year, season__season_round=season_round) + # Get all results in the ladder results = Result.objects.filter(ladder=ladder_object) + # Generate the results dictionary results_dict = {} - for result in results: + # Set the default result as an empty list if it is not already set. + # Then add the result to this list. results_dict.setdefault(result.player.id, []).append(result) return render(request, 'ladder/ladder/index.html', {'ladder': ladder_object, 'results_dict': results_dict})