Skip to content

Commit

Permalink
Views: Add new WDD awards view
Browse files Browse the repository at this point in the history
This lists a tournament's awards by number, to facilitate entry into
the WDD. The numbers are the ones used in the CSV files generated
for WDD upload.
Link to the new view from the tournament detail view.

Issue #289
  • Loading branch information
UEWBot committed Mar 10, 2024
1 parent b439fd9 commit 0faec47
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions visualiser/tournament/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ def round_scoring_system_obj(self):
raise InvalidScoringSystem(self.round_scoring_system)
return system

def non_power_awards(self):
"""
Returns a QuerySet of all awards other than "Best Country" awards.
"""
return self.awards.filter(power=None)

def award_number(self, award):
"""
Returns the number (1..n) for the specified (non-best country) award at the tournament
Expand Down
8 changes: 8 additions & 0 deletions visualiser/tournament/templates/tournaments/awards.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

{% block content %}
<h1><a href="{{ tournament.get_absolute_url }}">{{ tournament }}</a> {% trans "Awards" %}</h1>
{% if numbered_list %}
<ol>
{% for a in tournament.non_power_awards %}
<li>{{ a }}</li>
{% endfor %}
</ol>
{% else %}
<dl>
{% if tournament.is_finished %}
{% for tp in tournament.tournamentplayer_set.all %}
Expand All @@ -24,4 +31,5 @@ <h1><a href="{{ tournament.get_absolute_url }}">{{ tournament }}</a> {% trans "A
{% endfor %}
{% endif %}
</dl>
{% endif %}
{% endblock %}
7 changes: 4 additions & 3 deletions visualiser/tournament/templates/tournaments/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ <h1>{{ tournament }}</h1>
<li><a href="{% url 'round_index' tournament.id %}">{% trans "Round Index" %}</a></li>
</ul>
{% if tournament.is_finished %}
<p>{% trans "CSV files for World Diplomacy Database upload:" %}</p>
<p>{% trans "Information for adding the tournament to the World Diplomacy Database:" %}</p>
<ul>
<li><a href="{% url 'csv_classification' tournament.id %}">{% trans "Classification" %}</a></li>
<li><a href="{% url 'csv_boards' tournament.id %}">{% trans "Boards" %}</a></li>
<li><a href="{% url 'csv_classification' tournament.id %}">{% trans "Classification CSV file" %}</a></li>
<li><a href="{% url 'csv_boards' tournament.id %}">{% trans "Boards CSV file" %}</a></li>
<li><a href="{% url 'tournament_wdd_awards' tournament.id %}">{% trans "Award numbering" %}</a></li>
</ul>
{% endif %}
{% if user.is_active and tournament.editable %}
Expand Down
8 changes: 8 additions & 0 deletions visualiser/tournament/test_tournament_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,3 +934,11 @@ def test_enter_awards_post(self):
self.assertEqual(a.tournamentplayer_set.count(), 1)
# Cleanup
tp.awards.clear()


def test_tournament_wdd_awards(self):
# Should be viewable without logging in
response = self.client.get(reverse('tournament_wdd_awards',
args=(self.t1.pk,)),
secure=True)
self.assertEqual(response.status_code, 200)
6 changes: 5 additions & 1 deletion visualiser/tournament/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ def to_url(self, value):
path('player_prefs/<uuid:uuid>/', tournament_player_views.player_prefs,
name='player_prefs'),
path('awards/', tournament_views.tournament_simple,
{'template': 'awards'}, name='tournament_awards'),
{'template': 'awards', 'context': {'numbered_list': False}},
name='tournament_awards'),
path('wdd_awards/', tournament_views.tournament_simple,
{'template': 'awards', 'context': {'numbered_list': True}},
name='tournament_wdd_awards'),
path('enter_awards/', tournament_views.enter_awards, name='enter_awards'),
path('players/', include(tp_patterns)),
path('rounds/<int:round_num>/', include(round_patterns)),
Expand Down

0 comments on commit 0faec47

Please sign in to comment.