def get_table(self): """On adjudicator record pages, the table is the previous debates table.""" tournament = self.get_tournament() debateadjs = DebateAdjudicator.objects.filter(adjudicator=self.object, debate__round__seq__lt=tournament.current_round.seq, debate__round__draw_status=Round.STATUS_RELEASED, debate__round__silent=False).select_related( 'debate', 'debate__round').prefetch_related( 'debate__debateadjudicator_set', 'debate__debateadjudicator_set__adjudicator') debates = [da.debate for da in debateadjs] populate_teams(debates) populate_wins(debates) populate_confirmed_ballots(debates, motions=True, ballotsets=True) table = TabbycatTableBuilder(view=self, title="Previous Rounds", sort_key="Round") table.add_round_column([debate.round for debate in debates]) table.add_debate_results_columns(debates) table.add_debate_adjudicators_column(debates, show_splits=True, highlight_adj=self.object) if self.admin or tournament.pref('public_motions'): table.add_motion_column([debate.confirmed_ballot.motion if debate.confirmed_ballot else None for debate in debates]) table.add_debate_ballot_link_column(debates) return table
def debate_set_with_prefetches(self, filter_kwargs=None, ordering=('venue__name',), teams=True, adjudicators=True, speakers=True, divisions=True, ballotsubs=False, wins=False, ballotsets=False, venues=True, institutions=False): """Returns the debate set, with aff_team and neg_team populated. This is basically a prefetch-like operation, except that it also figures out which team is on which side, and sets attributes accordingly.""" from draw.prefetch import populate_teams from results.prefetch import populate_confirmed_ballots, populate_wins debates = self.debate_set.all() if filter_kwargs: debates = debates.filter(**filter_kwargs) if ballotsubs or ballotsets: debates = debates.prefetch_related('ballotsubmission_set', 'ballotsubmission_set__submitter') if adjudicators: debates = debates.prefetch_related('debateadjudicator_set__adjudicator') if divisions and self.tournament.pref('enable_divisions'): debates = debates.select_related('division', 'division__venue_group') if venues: debates = debates.select_related('venue', 'venue__group') if ordering: debates = debates.order_by(*ordering) # These functions populate relevant attributes of each debate, operating in-place if teams or speakers or wins or institutions: populate_teams(debates, speakers=speakers, institutions=institutions) # _aff_team, _aff_dt, _neg_team, _neg_dt if ballotsubs or ballotsets: populate_confirmed_ballots(debates, motions=True, ballotsets=ballotsets) if wins: populate_wins(debates) return debates