Skip to content

Commit

Permalink
Remove debate shortcuts for specific [debate]teams
Browse files Browse the repository at this point in the history
  • Loading branch information
tienne-B committed Jun 1, 2024
1 parent b47d749 commit 817de07
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 39 deletions.
37 changes: 3 additions & 34 deletions tabbycat/draw/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,6 @@ def _populate_teams(self):
self._team_properties[team_key] = dt.team
self._team_properties[dt_key] = dt

def _team_property(attr): # noqa: N805
"""Used to construct properties that rely on self._populate_teams()."""
@property
def _property(self):
if not hasattr(self, '_team_properties'):
self._populate_teams()
if attr in self._multiple_found:
raise MultipleDebateTeamsError("Multiple debate teams found for '%s' in debate ID %d. "
"Teams in debate are: %s." % (attr, self.id, self._teams_and_sides_display()))
try:
return self._team_properties[attr]
except KeyError:
raise NoDebateTeamFoundError("No debate team found for '%s' in debate ID %d. "
"Teams in debate are: %s." % (attr, self.id, self._teams_and_sides_display()))
return _property

@property
def teams(self):
# No need for _team_property overhead, this list is guaranteed to exist
Expand All @@ -192,25 +176,10 @@ def debateteams_ordered(self):
for side in self.round.tournament.sides:
yield self.get_dt(side)

aff_team = _team_property('0_team')
neg_team = _team_property('1_team')
bye_team = _team_property('-1_team')
og_team = _team_property('0_team')
oo_team = _team_property('1_team')
cg_team = _team_property('2_team')
co_team = _team_property('3_team')
aff_dt = _team_property('0_dt')
neg_dt = _team_property('1_dt')
bye_dt = _team_property('-1_dt')
og_dt = _team_property('0_dt')
oo_dt = _team_property('1_dt')
cg_dt = _team_property('2_dt')
co_dt = _team_property('3_dt')

def get_team(self, side: int) -> 'Team':
if not hasattr(self, '_team_properties'):
self._populate_teams()
return self._team_properties['%d_team' % side]
return self.teams[side]

def get_dt(self, side: int) -> 'DebateTeam':
"""dt = DebateTeam"""
Expand Down Expand Up @@ -240,7 +209,7 @@ def history(self):
try:
return self._history
except AttributeError:
self._history = self.aff_team.seen(self.neg_team, before_round=self.round.seq)
self._history = self.teams[DebateSide.AFF].seen(self.teams[DebateSide.NEG], before_round=self.round.seq)
return self._history

@property
Expand All @@ -263,7 +232,7 @@ def adjudicators(self):
def is_bye(self):
if not hasattr(self, '_team_properties'):
self._populate_teams()
return 'bye_dt' in self._team_properties
return '-1_dt' in self._team_properties


class DebateTeamManager(models.Manager):
Expand Down
4 changes: 2 additions & 2 deletions tabbycat/participants/templates/current_round/round_adj.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

{# (Two-team formats) #}
{% if pref.teams_in_debate == 2 %}
{% team_record_link debate.aff_team admin_page as aff %}
{% team_record_link debate.neg_team admin_page as neg %}
{% team_record_link debate.teams.0 admin_page as aff %}
{% team_record_link debate.teams.1 admin_page as neg %}

{% if debate.adjudicators|length > 1 and debateadjudicator.type == debateadjudicator.TYPE_CHAIR %}
{% if grammatical_person == "3" %}
Expand Down
3 changes: 2 additions & 1 deletion tabbycat/results/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils.translation import ngettext

from draw.models import Debate, DebateTeam
from draw.types import DebateSide
from options.utils import use_team_code_names_data_entry
from participants.models import Speaker, Team
from participants.templatetags.team_name_for_data_entry import team_name_for_data_entry
Expand Down Expand Up @@ -337,7 +338,7 @@ def initial_data(self):
# If sides are already confirmed, initialise the sides choice field
if self.choosing_sides and self.ballotsub.debate.sides_confirmed:
try:
initial['choose_sides'] = str(self.debate.aff_team.id) + "," + str(self.debate.neg_team.id)
initial['choose_sides'] = str(self.debate.teams[DebateSide.AFF].id) + "," + str(self.debate.teams[DebateSide.NEG].id)
except DebateTeam.DoesNotExist:
pass

Expand Down
4 changes: 2 additions & 2 deletions tabbycat/tournaments/tests/test_round_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_duplicate_venues(self):

def test_duplicate_team_names(self):
self.assertEqual(self.round.duplicate_team_names.count(), 0)
self.debates[0].aff_dt.team = self.teams[1][0]
self.debates[0].aff_dt.save()
self.debates[0].debateteams[DebateSide.AFF].team = self.teams[1][0]
self.debates[0].debateteams[DebateSide.AFF].save()
self.assertEqual(self.round.duplicate_team_names.count(), 1)
self.assertEqual(self.round.duplicate_team_names.first(), self.teams[1][0].short_name)

Expand Down

0 comments on commit 817de07

Please sign in to comment.