Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team conflict forms: Use team name corresponding to code name setting #2560

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tabbycat/adjallocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from actionlog.mixins import LogActionMixin
from actionlog.models import ActionLogEntry
from availability.utils import annotate_availability
from options.utils import use_team_code_names
from participants.models import Adjudicator, Region
from participants.prefetch import populate_feedback_scores
from tournaments.mixins import DebateDragAndDropMixin, TournamentMixin
Expand Down Expand Up @@ -143,7 +144,7 @@ class PanelAdjudicatorsIndexView(AdministratorMixin, TournamentMixin, TemplateVi
class TeamChoiceField(ModelChoiceField):

def label_from_instance(self, obj):
return obj.short_name
return obj.code_name if self.use_code_names else obj.short_name


class BaseAdjudicatorConflictsView(LogActionMixin, AdministratorMixin, TournamentMixin, ModelFormSetView):
Expand Down Expand Up @@ -205,10 +206,12 @@ class AdjudicatorTeamConflictsView(BaseAdjudicatorConflictsView):
def get_formset(self):
formset = super().get_formset()
all_adjs = self.tournament.adjudicator_set.order_by('name').all()
all_teams = self.tournament.team_set.order_by('short_name').all()
use_code_names = use_team_code_names(self.tournament, admin=True, user=self.request.user)
all_teams = self.tournament.team_set.order_by('code_name' if use_code_names else 'short_name').all()
for form in formset:
form.fields['adjudicator'].queryset = all_adjs # order alphabetically
form.fields['team'].queryset = all_teams # order alphabetically
form.fields['team'].use_code_names = use_code_names
return formset

def get_formset_queryset(self):
Expand Down Expand Up @@ -336,9 +339,11 @@ class TeamInstitutionConflictsView(BaseAdjudicatorConflictsView):

def get_formset(self):
formset = super().get_formset()
all_teams = self.tournament.team_set.order_by('short_name').all()
use_code_names = use_team_code_names(self.tournament, admin=True, user=self.request.user)
all_teams = self.tournament.team_set.order_by('code_name' if use_code_names else 'short_name').all()
for form in formset:
form.fields['team'].queryset = all_teams # order alphabetically
form.fields['team'].use_code_names = use_code_names
return formset

def get_formset_queryset(self):
Expand Down
Loading