def get_content_object_display(self, omit_tournament=False): obj = self.content_object if obj is None: return None model_name = self.content_type.model try: if model_name == 'ballotsubmission': if use_team_code_names(self.tournament, True): return obj.debate.matchup_codes else: return obj.debate.matchup elif model_name == 'debate': if use_team_code_names(self.tournament, True): return obj.debate.matchup_codes else: return obj.debate.matchup elif model_name == 'motion': return obj.reference elif model_name == 'adjudicatortestscorehistory': return obj.adjudicator.name + " (" + str(obj.score) + ")" elif model_name == 'adjudicatorfeedback': return obj.adjudicator.name elif model_name == 'tournament': return None if omit_tournament else obj.name elif model_name in ['round', 'adjudicator', 'breakcategory']: return obj.name else: return str(obj) except: return "<error displaying %s>" % model_name
def get_content_object_display(self, omit_tournament=False): obj = self.content_object if obj is None: return None model_name = self.content_type.model try: if model_name == 'ballotsubmission': if use_team_code_names(self.tournament, True): return obj.debate.matchup_codes else: return obj.debate.matchup elif model_name == 'debate': if use_team_code_names(self.tournament, True): return obj.debate.matchup_codes else: return obj.debate.matchup elif model_name == 'motion': return obj.reference elif model_name == 'adjudicatorbasescorehistory': return obj.adjudicator.name + " (" + str(obj.score) + ")" elif model_name == 'adjudicatorfeedback': return obj.adjudicator.name elif model_name == 'tournament': return None if omit_tournament else obj.name elif model_name in ['round', 'adjudicator', 'breakcategory']: return obj.name else: return str(obj) except Exception: return "<error displaying %s>" % model_name
def get_table(self): rounds = self.get_rounds() if not rounds: return TabbycatTableBuilder(view=self) # empty (as precaution) name_attr = 'code_name' if use_team_code_names(self.tournament, False) else 'short_name' # Obscure true rankings, in case client disabled JavaScript teams = self.tournament.team_set.prefetch_related( 'speaker_set').order_by(name_attr) # Can't use prefetch.populate_win_counts, since that doesn't exclude # silent rounds and future rounds appropriately opponents = self.tournament.pref('teams_in_debate') == 'two' add_team_round_results_public(teams, rounds, opponents=opponents) # Pre-sort, as Vue tables can't do two sort keys teams = sorted(teams, key=lambda t: (-t.points, getattr(t, name_attr))) key, title = ('points', _("Points")) if self.tournament.pref( 'teams_in_debate') == 'bp' else ('wins', _("Wins")) header = {'key': key, 'tooltip': title, 'icon': 'bar-chart'} table = TabbycatTableBuilder(view=self, sort_order='desc') table.add_team_columns(teams) table.add_column(header, [team.points for team in teams]) table.add_team_results_columns(teams, rounds) return table
def send_ballot_receipt_emails_to_adjudicators(ballots, debate): messages = [] round_name = _("%(tournament)s %(round)s @ %(room)s") % { 'tournament': str(debate.round.tournament), 'round': debate.round.name, 'room': debate.venue.name } subject = Template(debate.round.tournament.pref('ballot_email_subject')) message = Template(debate.round.tournament.pref('ballot_email_message')) context = {'DEBATE': round_name} use_codes = use_team_code_names(debate.round.tournament, False) for ballot in ballots: if 'adjudicator' in ballot: judge = ballot['adjudicator'] else: judge = debate.debateadjudicator_set.get( type=DebateAdjudicator.TYPE_CHAIR).adjudicator if judge.email is None: continue scores = "" for team in ballot['teams']: team_name = team['team'].code_name if use_codes else team[ 'team'].short_name scores += _("(%(side)s) %(team)s\n") % { 'side': team['side'], 'team': team_name } for speaker in team['speakers']: scores += _("- %(debater)s: %(score)s\n") % { 'debater': speaker['speaker'], 'score': speaker['score'] } context['USER'] = judge.name context['SCORES'] = scores messages.append( TournamentEmailMessage( subject, message, debate.round.tournament, debate.round, SentMessageRecord.EVENT_TYPE_BALLOT_CONFIRMED, judge, context)) try: get_connection().send_messages(messages) except SMTPException: logger.exception("Failed to send ballot receipt e-mails") raise except ConnectionError: logger.exception("Connection error sending ballot receipt e-mails") raise else: SentMessageRecord.objects.bulk_create( [message.as_sent_record() for message in messages])
def get_tables(self): adjudicators = self.tournament.adjudicator_set.select_related( 'institution') adjs_table = TabbycatTableBuilder(view=self, title=_("Adjudicators"), sort_key="name") adjs_table.add_adjudicator_columns(adjudicators) speakers = Speaker.objects.filter( team__tournament=self.tournament).select_related( 'team', 'team__institution').prefetch_related('team__speaker_set', 'categories') if use_team_code_names(self.tournament, self.admin): speakers = speakers.order_by('team__code_name') else: speakers = speakers.order_by('team__short_name') speakers_table = TabbycatTableBuilder(view=self, title=_("Speakers"), sort_key="team", admin=self.admin) speakers_table.add_speaker_columns(speakers) speakers_table.add_team_columns([speaker.team for speaker in speakers]) return [adjs_table, speakers_table]
def team_draw_email_generator(to, url, round_id): emails = [] round = Round.objects.get(id=round_id) tournament = round.tournament draw = round.debate_set_with_prefetches(speakers=True, divisions=False).all() use_codes = use_team_code_names(tournament, False) for debate in draw: matchup = debate.matchup_codes if use_codes else debate.matchup context = { 'ROUND': round.name, 'VENUE': debate.venue.name, 'PANEL': _assemble_panel(debate.adjudicators.with_positions()), 'DRAW': matchup } for dt in debate.debateteam_set.all(): context_team = context.copy() context_team[ 'TEAM'] = dt.team.code_name if use_codes else dt.team.short_name context_team['SIDE'] = dt.get_side_name(tournament=tournament) for speaker in dt.team.speakers: try: to.remove(speaker.id) except ValueError: continue context_user = context_team.copy() context_user['USER'] = speaker.name emails.append((context_user, speaker)) return emails
def get_context_data(self, **kwargs): ballot = self.object.ballotsubmission_set.filter(discarded=False).order_by('version').last() kwargs['motion'] = ballot.motion kwargs['result'] = ballot.result kwargs['use_code_names'] = use_team_code_names(self.tournament, False) kwargs['adjudicator'] = Adjudicator.objects.get(url_key=self.kwargs.get('url_key')) return super().get_context_data(**kwargs)
def team_draw_email_generator(to, round): emails = [] to_ids = {p.id for p in to} tournament = round.tournament draw = round.debate_set_with_prefetches(speakers=True).filter( debateteam__team__speaker__in=to) use_codes = use_team_code_names(tournament, False) for debate in draw: matchup = debate.matchup_codes if use_codes else debate.matchup context = { 'ROUND': round.name, 'VENUE': debate.venue.name, 'PANEL': _assemble_panel(debate.adjudicators.with_positions()), 'DRAW': matchup, } for dt in debate.debateteam_set.all(): context_team = context.copy() context_team[ 'TEAM'] = dt.team.code_name if use_codes else dt.team.short_name context_team['SIDE'] = dt.get_side_name( tournament=round.tournament) for speaker in dt.team.speakers: if not _check_in_to(speaker.id, to_ids): continue context_user = context_team.copy() context_user['USER'] = speaker.name emails.append((context_user, speaker)) return emails
def adjudicator_assignment_email_generator(to, url, round): emails = [] to_ids = {p.id for p in to} draw = round.debate_set_with_prefetches(speakers=False).filter( debateadjudicator__adjudicator__in=to) use_codes = use_team_code_names(round.tournament, False) for debate in draw: matchup = debate.matchup_codes if use_codes else debate.matchup context = { 'ROUND': round.name, 'VENUE': debate.venue.display_name if debate.venue is not None else _("TBA"), 'PANEL': _assemble_panel(debate.adjudicators.with_positions()), 'DRAW': matchup, } for adj, pos in debate.adjudicators.with_positions(): if not _check_in_to(adj.id, to_ids): continue context_user = context.copy() context_user['USER'] = adj.name context_user['POSITION'] = adj_position_names[pos] if adj.url_key: context_user['URL'] = url + adj.url_key + '/' emails.append((context_user, adj)) return emails
def get_table(self): rounds = self.get_rounds() if not rounds: return TabbycatTableBuilder(view=self) # empty (as precaution) name_attr = 'code_name' if use_team_code_names(self.tournament, False) else 'short_name' # Obscure true rankings, in case client disabled JavaScript teams = self.tournament.team_set.prefetch_related('speaker_set').order_by(name_attr) # Can't use prefetch.populate_win_counts, since that doesn't exclude # silent rounds and future rounds appropriately opponents = self.tournament.pref('teams_in_debate') == 'two' add_team_round_results_public(teams, rounds, opponents=opponents) # Pre-sort, as Vue tables can't do two sort keys teams = sorted(teams, key=lambda t: (-t.points, getattr(t, name_attr))) key, title = ('points', _("Points")) if self.tournament.pref('teams_in_debate') == 'bp' else ('wins', _("Wins")) header = {'key': key, 'tooltip': title, 'icon': 'bar-chart'} table = TabbycatTableBuilder(view=self, sort_order='desc') table.add_team_columns(teams) table.add_column(header, [team.points for team in teams]) table.add_team_results_columns(teams, rounds) return table
def get_context_data(self, **kwargs): team_codes = use_team_code_names(self.tournament, admin=self.for_admin) kwargs["team_codes"] = json.dumps(team_codes) adjudicators = [] for adj in self.tournament.relevant_adjudicators.all().select_related('institution', 'checkin_identifier'): try: code = adj.checkin_identifier.barcode except ObjectDoesNotExist: code = None adjudicators.append({ 'id': adj.id, 'name': adj.name, 'type': 'Adjudicator', 'identifier': [code], 'locked': False, 'independent': adj.independent, 'institution': adj.institution.serialize if adj.institution else None, }) kwargs["adjudicators"] = json.dumps(adjudicators) speakers = [] for speaker in Speaker.objects.filter(team__tournament=self.tournament).select_related('team', 'team__institution', 'checkin_identifier'): try: code = speaker.checkin_identifier.barcode except ObjectDoesNotExist: code = None speakers.append({ 'id': speaker.id, 'name': speaker.name, 'type': 'Speaker', 'identifier': [code], 'locked': False, 'team': speaker.team.code_name if team_codes else speaker.team.short_name, 'institution': speaker.team.institution.serialize if speaker.team.institution else None, }) kwargs["speakers"] = json.dumps(speakers) return super().get_context_data(**kwargs)
def get_context_data(self, **kwargs): kwargs[ 'motion'] = self.object.confirmed_ballot.motion or self.object.round.motion_set.first( ) kwargs['result'] = self.object.confirmed_ballot.result kwargs['use_code_names'] = use_team_code_names(self.tournament, False) return super().get_context_data(**kwargs)
def team_record_link(team, admin, tournament=None, style=True): """Team record links are used often, so this template tag just reduces clutter in templates, in particular in translated strings.""" if not team: return "" if not tournament: tournament = team.tournament if use_team_code_names(tournament, admin): name = team.code_name else: name = team.short_name if admin: url = reverse_tournament('participants-team-record', tournament, kwargs={'pk': team.pk}) else: url = reverse_tournament('participants-public-team-record', tournament, kwargs={'pk': team.pk}) classes = 'class="list-group-item-text alert-link"' if style else '' return mark_safe("""<a href="%(url)s" %(style)s>%(name)s</a>""" % { 'url': url, 'style': classes, 'name': name })
def get_context_data(self, **kwargs): team_codes = use_team_code_names(self.tournament, admin=self.for_admin) kwargs["team_codes"] = json.dumps(team_codes) adjudicators = [] for adj in self.tournament.relevant_adjudicators.all().select_related( 'institution', 'checkin_identifier'): try: code = adj.checkin_identifier.barcode except ObjectDoesNotExist: code = None adjudicators.append({ 'id': adj.id, 'name': adj.name, 'type': 'Adjudicator', 'identifier': [code], 'locked': False, 'independent': adj.independent, 'institution': adj.institution.serialize if adj.institution else None, }) kwargs["adjudicators"] = json.dumps(adjudicators) speakers = [] for speaker in Speaker.objects.filter( team__tournament=self.tournament).select_related( 'team', 'team__institution', 'checkin_identifier'): try: code = speaker.checkin_identifier.barcode except ObjectDoesNotExist: code = None speakers.append({ 'id': speaker.id, 'name': speaker.name, 'type': 'Speaker', 'identifier': [code], 'locked': False, 'team': speaker.team.code_name if team_codes else speaker.team.short_name, 'institution': speaker.team.institution.serialize if speaker.team.institution else None, }) kwargs["speakers"] = json.dumps(speakers) return super().get_context_data(**kwargs)
def send_mail_to_adjs(round): tournament = round.tournament draw = round.debate_set_with_prefetches(speakers=False, divisions=False).all() use_codes = use_team_code_names(tournament, False) subject = Template(tournament.pref('adj_email_subject_line')) body = Template(tournament.pref('adj_email_message')) messages = [] adj_position_names = { AdjudicatorAllocation.POSITION_CHAIR: _("the chair"), AdjudicatorAllocation.POSITION_ONLY: _("the only"), AdjudicatorAllocation.POSITION_PANELLIST: _("a panellist"), AdjudicatorAllocation.POSITION_TRAINEE: _("a trainee"), } def _assemble_panel(adjs): adj_string = [] for adj, pos in adjs: adj_string.append("%s (%s)" % (adj.name, adj_position_names[pos])) return ", ".join(adj_string) for debate in draw: matchup = debate.matchup_codes if use_codes else debate.matchup context = { 'ROUND': round.name, 'VENUE': debate.venue.name if hasattr(debate, 'venue') else _("TBA"), 'PANEL': _assemble_panel(debate.adjudicators.with_positions()), 'DRAW': matchup } for adj, pos in debate.adjudicators.with_positions(): if adj.email is None: continue context_user = context.copy() context_user['USER'] = adj.name context_user['POSITION'] = adj_position_names[pos] messages.append( TournamentEmailMessage(subject, body, tournament, round, SentMessageRecord.EVENT_TYPE_DRAW, adj, context_user)) try: get_connection().send_messages(messages) except SMTPException: logger.exception("Failed to send adjudicator e-mails") raise except ConnectionError: logger.exception("Connection error sending adjudicator e-mails") raise else: SentMessageRecord.objects.bulk_create( [message.as_sent_record() for message in messages])
def get_context_data(self, **kwargs): kwargs['ballots'] = json.dumps(self.get_ballots_dicts()) motions = self.round.motion_set.order_by('seq') kwargs['motions'] = json.dumps([{ 'seq': m.seq, 'text': m.text } for m in motions]) kwargs['use_team_code_names'] = use_team_code_names( self.tournament, False) return super().get_context_data(**kwargs)
def get_context_data(self, **kwargs): kwargs['ballots'] = json.dumps(self.get_ballots_dicts()) kwargs['ordinals'] = [ordinal(i) for i in range(1, 5)] motions = self.round.roundmotion_set.order_by('seq').select_related( 'motion') kwargs['motions'] = json.dumps([{ 'seq': m.seq, 'text': m.motion.text } for m in motions]) kwargs['use_team_code_names'] = use_team_code_names( self.tournament, False) return super().get_context_data(**kwargs)
def send_mail_to_adjs(round): tournament = round.tournament draw = round.debate_set_with_prefetches(speakers=False, divisions=False).all() use_codes = use_team_code_names(tournament, False) subject = Template(tournament.pref('adj_email_subject_line')) body = Template(tournament.pref('adj_email_message')) messages = [] adj_position_names = { AdjudicatorAllocation.POSITION_CHAIR: _("the chair"), AdjudicatorAllocation.POSITION_ONLY: _("the only"), AdjudicatorAllocation.POSITION_PANELLIST: _("a panellist"), AdjudicatorAllocation.POSITION_TRAINEE: _("a trainee"), } def _assemble_panel(adjs): adj_string = [] for adj, pos in adjs: adj_string.append("%s (%s)" % (adj.name, adj_position_names[pos])) return ", ".join(adj_string) for debate in draw: matchup = debate.matchup_codes if use_codes else debate.matchup context = { 'ROUND': round.name, 'VENUE': debate.venue.display_name if debate.venue is not None else _("TBA"), 'PANEL': _assemble_panel(debate.adjudicators.with_positions()), 'DRAW': matchup } for adj, pos in debate.adjudicators.with_positions(): if adj.email is None: continue context_user = context.copy() context_user['USER'] = adj.name context_user['POSITION'] = adj_position_names[pos] messages.append(TournamentEmailMessage(subject, body, tournament, round, SentMessageRecord.EVENT_TYPE_DRAW, adj, context_user)) try: get_connection().send_messages(messages) except SMTPException: logger.exception("Failed to send adjudicator e-mails") raise except ConnectionError: logger.exception("Connection error sending adjudicator e-mails") raise else: SentMessageRecord.objects.bulk_create([message.as_sent_record() for message in messages])
def construct_info(self, venue, source, source_p, target, target_p): if hasattr(source, 'name'): source_n = source.name elif use_team_code_names(self.tournament, False): source_n = source.code_name else: source_n = source.short_name return { 'venue': venue.serialize() if venue else '', 'authorInstitution': source.institution.code if source.institution else _("Unaffiliated"), 'author': source_n, 'authorPosition': source_p, 'target': target.name, 'targetPosition': target_p, }
def get_tables(self): adjudicators = self.tournament.adjudicator_set.select_related('institution') adjs_table = TabbycatTableBuilder(view=self, title=_("Adjudicators"), sort_key="name") adjs_table.add_adjudicator_columns(adjudicators) speakers = Speaker.objects.filter(team__tournament=self.tournament).select_related( 'team', 'team__institution').prefetch_related('team__speaker_set', 'categories') if use_team_code_names(self.tournament, self.admin): speakers = speakers.order_by('team__code_name') else: speakers = speakers.order_by('team__short_name') speakers_table = TabbycatTableBuilder(view=self, title=_("Speakers"), sort_key="team", admin=self.admin) speakers_table.add_speaker_columns(speakers) speakers_table.add_team_columns([speaker.team for speaker in speakers]) return [adjs_table, speakers_table]
def adjudicator_assignment_email_generator(to, url, round_id): emails = [] round = Round.objects.get(id=round_id) tournament = round.tournament draw = round.debate_set_with_prefetches(speakers=False, divisions=False).all() use_codes = use_team_code_names(tournament, False) for debate in draw: matchup = debate.matchup_codes if use_codes else debate.matchup context = { 'ROUND': round.name, 'VENUE': debate.venue.display_name if debate.venue is not None else _("TBA"), 'PANEL': _assemble_panel(debate.adjudicators.with_positions()), 'DRAW': matchup } for adj, pos in debate.adjudicators.with_positions(): try: to.remove(adj.id) except ValueError: continue context_user = context.copy() context_user['USER'] = adj.name context_user['POSITION'] = adj_position_names[pos] if adj.url_key: context_user['URL'] = url + adj.url_key + '/' emails.append((context_user, adj)) return emails
def get_team_short_name(self, team): use_code_names = use_team_code_names(self.tournament, admin=False) return team.code_name if use_code_names else team.short_name
def matchup_description(self, debate): if use_team_code_names(self.tournament, False): return debate.matchup_codes else: return debate.matchup
def get_context_data(self, **kwargs): kwargs['ballots'] = json.dumps(self.get_ballots_dicts()) motions = self.round.motion_set.order_by('seq') kwargs['motions'] = json.dumps([{'seq': m.seq, 'text': m.text} for m in motions]) kwargs['use_team_code_names'] = use_team_code_names(self.tournament, False) return super().get_context_data(**kwargs)
def readable_ballotsub_result(debateresult): """ Make a human-readable representation of a debate result """ def get_display_name(dt, t, use_codes): return { 'team': dt.team.code_name if use_codes else dt.team.short_name, 'side': dt.get_side_abbr(t), } def format_dt(dt, t, use_codes): # Translators: e.g. "{Melbourne 1} as {OG}", "{Cape Town 1} as {CO}" return _("%(team)s as %(side)s") % get_display_name(dt, t, use_codes) t = debateresult.tournament use_codes = use_team_code_names(t, True) try: if t.pref('teams_in_debate') == 'two': result_winner = _("%(team)s (%(side)s) won") % get_display_name( debateresult.winning_dt(), t, use_codes) # Translators: The team here is the losing team result = _("vs %(team)s (%(side)s)") % get_display_name( debateresult.losing_dt(), t, use_codes) elif not debateresult.is_voting and debateresult.is_elimination: result_winner = _("Advancing: %(advancing_list)s<br>") % { 'advancing_list': ", ".join( format_dt(dt, t, use_codes) for dt in debateresult.advancing_dt()), } result = _("Eliminated: %(eliminated_list)s") result = result % { 'eliminated_list': ", ".join( format_dt(dt, t, use_codes) for dt in debateresult.eliminated_dt()), } else: # BP preliminary round ordered = debateresult.get_ranked_dt() result_winner = _("1st: %(first_team)s<br>") % { 'first_team': format_dt(ordered[0], t, use_codes) } result = _("2nd: %(second_team)s<br>\n" "3rd: %(third_team)s<br>\n" "4th: %(fourth_team)s") result = result % { 'second_team': format_dt(ordered[1], t, use_codes), 'third_team': format_dt(ordered[2], t, use_codes), 'fourth_team': format_dt(ordered[3], t, use_codes), } except (IndexError, AttributeError): logger.warning("Error constructing latest result string", exc_info=True) if use_codes: matchup = debateresult.debate.matchup_codes else: matchup = debateresult.debate.matchup result_winner = _("Error with result for %(debate)s") % { 'debate': matchup } result = "" return result_winner, result
def _use_team_code_names(self): return use_team_code_names(self.tournament, self.admin)
def ballots_email_generator(to, debate): # "to" is unused emails = [] tournament = debate.round.tournament results = DebateResult(debate.confirmed_ballot) round_name = _("%(tournament)s %(round)s @ %(room)s") % { 'tournament': str(tournament), 'round': debate.round.name, 'room': debate.venue.name } use_codes = use_team_code_names(tournament, False) def _create_ballot(result, scoresheet): ballot = "<ul>" for side, (side_name, pos_names) in zip(tournament.sides, side_and_position_names(tournament)): side_string = "" if tournament.pref('teams_in_debate') == 'bp': side_string += _( "<li>%(side)s: %(team)s (%(points)d points with %(speaks)s total speaks)" ) points = 4 - scoresheet.rank(side) else: side_string += _( "<li>%(side)s: %(team)s (%(points)s - %(speaks)s total speaks)" ) points = _("Win") if side in scoresheet.winners() else _( "Loss") ballot += side_string % { 'side': side_name, 'team': result.debateteams[side].team.code_name if use_codes else result.debateteams[side].team.short_name, 'speaks': formats.localize(scoresheet.get_total(side)), 'points': points, } ballot += "<ul>" for pos, pos_name in zip(tournament.positions, pos_names): ballot += _("<li>%(pos)s: %(speaker)s (%(score)s)</li>") % { 'pos': pos_name, 'speaker': result.get_speaker(side, pos).name, 'score': formats.localize(scoresheet.get_score(side, pos)), } ballot += "</ul></li>" ballot += "</ul>" return mark_safe(ballot) if isinstance(results, DebateResultByAdjudicatorWithScores): for adj, ballot in results.scoresheets.items(): if adj.email is None: # As "to" is None, must check if eligible email continue context = { 'DEBATE': round_name, 'USER': adj.name, 'SCORES': _create_ballot(results, ballot) } emails.append((context, adj)) elif isinstance(results, ConsensusDebateResultWithScores): context = { 'DEBATE': round_name, 'SCORES': _create_ballot(results, results.scoresheet) } for adj in debate.debateadjudicator_set.all().select_related( 'adjudicator'): if adj.adjudicator.email is None: continue context_user = context.copy() context_user['USER'] = adj.adjudicator.name emails.append((context_user, adj.adjudicator)) return emails
def get_context_data(self, **kwargs): kwargs['motion'] = self.object.confirmed_ballot.motion kwargs['result'] = self.object.confirmed_ballot.result kwargs['use_code_names'] = use_team_code_names(self.tournament, False) return super().get_context_data(**kwargs)
def readable_ballotsub_result(ballotsub): """ Make a human-readable representation of a debate result """ def format_dt(dt, t, use_codes): # Translators: e.g. "{Melbourne 1} as {OG}", "{Cape Town 1} as {CO}" return _("%(team_name)s as %(side_abbr)s") % { 'team_name': dt.team.code_name if use_codes else dt.team.short_name, 'side_abbr': dt.get_side_name(t, 'abbr') } t = ballotsub.debate.round.tournament team_scores = ballotsub.teamscore_set.all() use_codes = use_team_code_names(t, True) try: if t.pref('teams_in_debate') == 'two': winner = None loser = None for teamscore in team_scores: if teamscore.win: winner = teamscore.debate_team else: loser = teamscore.debate_team result_winner = _("%(winner)s (%(winner_side)s) won") result_winner = result_winner % { 'winner': winner.team.code_name if use_codes else winner.team.short_name, 'winner_side': winner.get_side_name(t, 'abbr'), } result = _("vs %(loser)s (%(loser_side)s)") result = result % { 'loser': loser.team.code_name if use_codes else loser.team.short_name, 'loser_side': loser.get_side_name(t, 'abbr'), } elif ballotsub.debate.round.is_break_round: advancing = [] eliminated = [] for teamscore in team_scores: if teamscore.win: advancing.append(teamscore.debate_team) else: eliminated.append(teamscore.debate_team) result_winner = _("Advancing: %(advancing_list)s<br>\n") result_winner = result_winner % { 'advancing_list': ", ".join(format_dt(dt, t, use_codes) for dt in advancing) } result = _("Eliminated: %(eliminated_list)s") result = result % { 'eliminated_list': ", ".join(format_dt(dt, t, use_codes) for dt in eliminated), } else: # BP preliminary round ordered = [None] * 4 for teamscore in team_scores: ordered[teamscore.points] = teamscore.debate_team result_winner = _("1st: %(first_team)s<br>\n") result_winner = result_winner % { 'first_team': format_dt(ordered[3], t, use_codes) } result = _("2nd: %(second_team)s<br>\n" "3rd: %(third_team)s<br>\n" "4th: %(fourth_team)s") result = result % { 'second_team': format_dt(ordered[2], t, use_codes), 'third_team': format_dt(ordered[1], t, use_codes), 'fourth_team': format_dt(ordered[0], t, use_codes), } except (IndexError, AttributeError): logger.warning("Error constructing latest result string", exc_info=True) if use_codes: matchup = ballotsub.debate.matchup_codes else: matchup = ballotsub.debate.matchup result_winner = _("Error with result for %(debate)s") % { 'debate': matchup } result = "" return result_winner, result
def matchup_description(self): if use_team_code_names(self.tournament, False): return self.object.matchup_codes else: return self.object.matchup