def get_context_data(self, **kwargs): t = self.tournament updates = 10 # Number of items to fetch kwargs["round"] = t.current_round kwargs["tournament_slug"] = t.slug kwargs["readthedocs_version"] = settings.READTHEDOCS_VERSION kwargs["blank"] = not (t.team_set.exists() or t.adjudicator_set.exists() or t.venue_set.exists()) actions = ActionLogEntry.objects.filter(tournament=t).prefetch_related( 'content_object', 'user').order_by('-timestamp')[:updates] kwargs["initialActions"] = json.dumps([a.serialize for a in actions]) debates = t.current_round.debate_set.filter( ballotsubmission__confirmed=True, ).order_by( '-ballotsubmission__timestamp')[:updates] populate_confirmed_ballots(debates, results=True) subs = [d._confirmed_ballot.serialize_like_actionlog for d in debates] kwargs["initialBallots"] = json.dumps(subs) status = t.current_round.draw_status kwargs["total_debates"] = t.current_round.debate_set.count() if status == Round.STATUS_CONFIRMED or status == Round.STATUS_RELEASED: ballots = BallotSubmission.objects.filter( debate__round=t.current_round, discarded=False).select_related('submitter', 'debate') stats = [{'ballot': bs.serialize(t)} for bs in ballots] kwargs["initial_graph_data"] = json.dumps(stats) else: kwargs["initial_graph_data"] = json.dumps([]) return super().get_context_data(**kwargs)
def get_table(self): """On team record pages, the table is the results table.""" tournament = self.get_tournament() teamscores = TeamScore.objects.filter(debate_team__team=self.object, ballot_submission__confirmed=True, debate_team__debate__round__seq__lt=tournament.current_round.seq, debate_team__debate__round__draw_status=Round.STATUS_RELEASED, debate_team__debate__round__silent=False).select_related( 'debate_team__debate', 'debate_team__debate__round').prefetch_related( 'debate_team__debate__debateadjudicator_set__adjudicator') debates = [ts.debate_team.debate for ts in teamscores] populate_opponents([ts.debate_team for ts in teamscores]) populate_confirmed_ballots(debates, motions=True, ballotsets=True) table = TabbycatTableBuilder(view=self, title="Results", sort_key="Round") table.add_round_column([debate.round for debate in debates]) table.add_debate_result_by_team_columns(teamscores) table.add_debate_adjudicators_column(debates, show_splits=True) 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 get_table(self): """On adjudicator record pages, the table is the previous debates table.""" debateadjs = DebateAdjudicator.objects.filter( adjudicator=self.object, ).select_related( 'debate__round').prefetch_related( Prefetch('debate__debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related( 'adjudicator__institution')), 'debate__debateteam_set__team__speaker_set', 'debate__round__motion_set', ) if not self.admin and not self.tournament.pref('all_results_released'): debateadjs = debateadjs.filter( debate__round__draw_status=Round.STATUS_RELEASED, debate__round__silent=False, debate__round__seq__lt=self.tournament.current_round.seq, ) debates = [da.debate for da in debateadjs] populate_wins(debates) populate_confirmed_ballots(debates, motions=True, results=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 self.tournament.pref('public_motions'): table.add_debate_motion_column(debates) table.add_debate_ballot_link_column(debates) return table
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
def get_table(self): """On adjudicator record pages, the table is the previous debates table.""" debateadjs = DebateAdjudicator.objects.filter( adjudicator=self.object, ).select_related( 'debate__round' ).prefetch_related( Prefetch('debate__debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related('adjudicator__institution')), 'debate__debateteam_set__team__speaker_set', 'debate__round__motion_set', ) if not self.admin and not self.tournament.pref('all_results_released'): debateadjs = debateadjs.filter( debate__round__draw_status=Round.STATUS_RELEASED, debate__round__silent=False, debate__round__seq__lt=self.tournament.current_round.seq, ) debates = [da.debate for da in debateadjs] populate_wins(debates) populate_confirmed_ballots(debates, motions=True, results=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 self.tournament.pref('public_motions'): table.add_debate_motion_column(debates) table.add_debate_ballot_link_column(debates) return table
def add_rounds(self): results_prefetch = Prefetch('ballotsubmission_set', queryset=BallotSubmission.objects.filter(confirmed=True).prefetch_related( 'speakerscore_set', 'speakerscorebyadj_set', 'teamscore_set')) veto_prefetch = Prefetch('debateteammotionpreference_set', queryset=DebateTeamMotionPreference.objects.filter( preference=3, ballot_submission__confirmed=True, )) dt_prefetch = Prefetch('debateteam_set', queryset=DebateTeam.objects.all().select_related( 'team', 'team__institution', ).prefetch_related(veto_prefetch)) debate_prefetch = Prefetch('debate_set', queryset=Debate.objects.all().prefetch_related( 'debateadjudicator_set', dt_prefetch, results_prefetch, )) for round in self.t.round_set.all().prefetch_related(debate_prefetch, 'motion_set').order_by('seq'): populate_confirmed_ballots(round.debate_set.all(), motions=True, results=True) populate_wins(round.debate_set.all()) round_tag = SubElement(self.root, 'round', { 'name': round.name, 'abbreviation': round.abbreviation, 'elimination': str(round.stage == Round.STAGE_ELIMINATION).lower(), 'feedback-weight': str(round.feedback_weight), }) if round.stage == Round.STAGE_ELIMINATION: round_tag.set('break-category', BREAK_CATEGORY_PREFIX + str(round.break_category_id)) if round.starts_at is not None and round.starts_at != "": round_tag.set('start', str(round.starts_at)) motion = round.motion_set.first() for debate in round.debate_set.all(): self.add_debates(round_tag, motion, debate)
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 adjallocation.models import DebateAdjudicator from draw.models import DebateTeam 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( Prefetch('debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related( 'adjudicator__institution')), ) if divisions and self.tournament.pref('enable_divisions'): debates = debates.select_related('division', 'division__venue_category') if venues: debates = debates.select_related('venue').prefetch_related( 'venue__venuecategory_set') if teams or wins or institutions or speakers: debates = debates.prefetch_related( Prefetch('debateteam_set', queryset=DebateTeam.objects.select_related( 'team__institution' if institutions else 'team'))) if speakers: debates = debates.prefetch_related( 'debateteam_set__team__speaker_set') if ordering: debates = debates.order_by(*ordering) # These functions populate relevant attributes of each debate, operating in-place if ballotsubs or ballotsets: populate_confirmed_ballots(debates, motions=True, ballotsets=ballotsets) if wins: populate_wins(debates) return debates
def _debateteam_queryset_operations(queryset): # this is also used by get_feedback_progress debateteams = queryset.filter( debate__ballotsubmission__confirmed=True, debate__round__silent=False, debate__round__stage=Round.STAGE_PRELIMINARY ).select_related('debate', 'debate__round').prefetch_related( 'debate__debateadjudicator_set__adjudicator') populate_confirmed_ballots([dt.debate for dt in debateteams], ballotsets=True) return debateteams
def _debateteam_queryset_operations(queryset): # this is also used by get_feedback_progress debateteams = queryset.filter( debate__ballotsubmission__confirmed=True, debate__round__silent=False, debate__round__stage=Round.STAGE_PRELIMINARY ).select_related('debate', 'debate__round').prefetch_related( 'debate__debateadjudicator_set__adjudicator') populate_confirmed_ballots([dt.debate for dt in debateteams], results=True) return debateteams
def get_table(cls, view, participant): """On team record pages, the table is the results table.""" table = TeamResultTableBuilder(view=view, title=view.table_title, sort_key="round") tournament = view.tournament teamscores = TeamScore.objects.filter( debate_team__team=participant, ballot_submission__confirmed=True, ).select_related( 'debate_team__debate__round__tournament', ).prefetch_related( Prefetch('debate_team__debate__debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related( 'adjudicator__institution')), 'debate_team__debate__debateteam_set__team', 'debate_team__debate__round__motion_set', Prefetch('debate_team__speakerscore_set', queryset=SpeakerScore.objects.filter( ballot_submission__confirmed=True).select_related( 'speaker').order_by('position'), to_attr='speaker_scores'), ).order_by('debate_team__debate__round__seq') if not table.admin and not tournament.pref('all_results_released'): teamscores = teamscores.filter( debate_team__debate__round__draw_status=Round.STATUS_RELEASED, debate_team__debate__round__silent=False, debate_team__debate__round__completed=True, ) debates = [ts.debate_team.debate for ts in teamscores] populate_opponents([ts.debate_team for ts in teamscores]) populate_confirmed_ballots(debates, motions=True, results=True) table.add_round_column([debate.round for debate in debates]) table.add_debate_result_by_team_column(teamscores) table.add_cumulative_team_points_column(teamscores) if table.admin or tournament.pref( 'all_results_released') and tournament.pref( 'speaker_tab_released') and tournament.pref( 'speaker_tab_limit') == 0: table.add_speaker_scores_column(teamscores) table.add_debate_side_by_team_column(teamscores) table.add_debate_adjudicators_column(debates, show_splits=True) if table.admin or tournament.pref('public_motions'): table.add_debate_motion_column(debates) if not table.private_url: 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, wins=False, results=False, venues=True, institutions=False, check_ins=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 adjallocation.models import DebateAdjudicator from draw.models import DebateTeam from participants.models import Speaker from results.prefetch import populate_confirmed_ballots, populate_wins, populate_checkins debates = self.debate_set.all() if filter_kwargs: debates = debates.filter(**filter_kwargs) if results: debates = debates.prefetch_related('ballotsubmission_set', 'ballotsubmission_set__submitter') if adjudicators: debates = debates.prefetch_related( Prefetch('debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related('adjudicator__institution')), ) if divisions and self.tournament.pref('enable_divisions'): debates = debates.select_related('division', 'division__venue_category') if venues: debates = debates.select_related('venue').prefetch_related('venue__venuecategory_set') if check_ins: debates = debates.select_related('checkin_identifier') if teams or wins or institutions or speakers: debateteam_prefetch_queryset = DebateTeam.objects.select_related('team') if institutions: debateteam_prefetch_queryset = debateteam_prefetch_queryset.select_related('team__institution') if speakers: debateteam_prefetch_queryset = debateteam_prefetch_queryset.prefetch_related( Prefetch('team__speaker_set', queryset=Speaker.objects.order_by('name'))) debates = debates.prefetch_related( Prefetch('debateteam_set', queryset=debateteam_prefetch_queryset)) if ordering: debates = debates.order_by(*ordering) # These functions populate relevant attributes of each debate, operating in-place if results: populate_confirmed_ballots(debates, motions=True, results=True) if wins: populate_wins(debates) if check_ins: populate_checkins(debates, self.tournament) return debates
def get_table(self): """On team record pages, the table is the results table.""" tournament = self.tournament teamscores = TeamScore.objects.filter( debate_team__team=self.object, ballot_submission__confirmed=True, ).select_related( 'debate_team__debate__round__tournament' ).prefetch_related( Prefetch('debate_team__debate__debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related('adjudicator__institution')), 'debate_team__debate__debateteam_set__team', 'debate_team__debate__round__motion_set', Prefetch('debate_team__speakerscore_set', queryset=SpeakerScore.objects.filter(ballot_submission__confirmed=True).select_related('speaker').order_by('position'), to_attr='speaker_scores'), ).order_by('debate_team__debate__round__seq') if not self.admin and not tournament.pref('all_results_released'): teamscores = teamscores.filter( debate_team__debate__round__draw_status=Round.STATUS_RELEASED, debate_team__debate__round__silent=False, debate_team__debate__round__seq__lt=tournament.current_round.seq ) debates = [ts.debate_team.debate for ts in teamscores] populate_opponents([ts.debate_team for ts in teamscores]) populate_confirmed_ballots(debates, motions=True, results=True) table = TeamResultTableBuilder(view=self, title=_("Results"), sort_key="round") table.add_round_column([debate.round for debate in debates]) table.add_debate_result_by_team_column(teamscores) table.add_cumulative_team_points_column(teamscores) if self.admin or tournament.pref('all_results_released') and tournament.pref('speaker_tab_released') and tournament.pref('speaker_tab_limit') == 0: table.add_speaker_scores_column(teamscores) table.add_debate_side_by_team_column(teamscores) table.add_debate_adjudicators_column(debates, show_splits=True) if self.admin or tournament.pref('public_motions'): table.add_debate_motion_column(debates) table.add_debate_ballot_link_column(debates) return table
def get_table(cls, view, participant): """On adjudicator record pages, the table is the previous debates table.""" table = TabbycatTableBuilder(view=view, title=view.table_title, sort_key="round") debateadjs = DebateAdjudicator.objects.filter( adjudicator=participant, ).select_related( 'debate__round', 'debate__round__tournament', ).prefetch_related( Prefetch('debate__debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related( 'adjudicator__institution')), 'debate__debateteam_set__team__speaker_set', 'debate__round__motion_set', ) if not table.admin and not view.tournament.pref( 'all_results_released') and not table.private_url: debateadjs = debateadjs.filter( debate__round__draw_status=Round.STATUS_RELEASED, debate__round__silent=False, debate__round__completed=True, ) elif table.private_url: debateadjs = debateadjs.filter( debate__round__draw_status=Round.STATUS_RELEASED) debates = [da.debate for da in debateadjs] populate_wins(debates) populate_confirmed_ballots(debates, motions=True, results=True) 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=participant) if table.admin or view.tournament.pref('public_motions'): table.add_debate_motion_column(debates) table.add_debate_ballot_link_column(debates) return table
def get_table(self): """On team record pages, the table is the results table.""" tournament = self.get_tournament() teamscores = TeamScore.objects.filter( debate_team__team=self.object, ballot_submission__confirmed=True, debate_team__debate__round__draw_status=Round.STATUS_RELEASED ).select_related('debate_team__debate__round').prefetch_related( Prefetch('debate_team__debate__debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related( 'adjudicator__institution')), 'debate_team__debate__debateteam_set') if not tournament.pref('all_results_released'): teamscores = teamscores.filter( debate_team__debate__round__silent=False, debate_team__debate__round__seq__lt=tournament.current_round. seq) debates = [ts.debate_team.debate for ts in teamscores] populate_opponents([ts.debate_team for ts in teamscores]) populate_confirmed_ballots(debates, motions=True, ballotsets=True) table = TabbycatTableBuilder(view=self, title="Results", sort_key="Round") table.add_round_column([debate.round for debate in debates]) table.add_debate_result_by_team_columns(teamscores) table.add_debate_adjudicators_column(debates, show_splits=True) 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, wins=False, results=False, venues=True, institutions=False, check_ins=False, iron=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 adjallocation.models import DebateAdjudicator from draw.models import DebateTeam from participants.models import Speaker from results.prefetch import populate_confirmed_ballots, populate_wins, populate_checkins debates = self.debate_set.all() if filter_kwargs: debates = debates.filter(**filter_kwargs) if results: debates = debates.prefetch_related( 'ballotsubmission_set', 'ballotsubmission_set__submitter', 'ballotsubmission_set__participant_submitter') if adjudicators: debates = debates.prefetch_related( Prefetch('debateadjudicator_set', queryset=DebateAdjudicator.objects.select_related( 'adjudicator__institution')), ) if venues: debates = debates.select_related('venue').prefetch_related( 'venue__venuecategory_set') if check_ins: debates = debates.select_related('checkin_identifier') if teams or wins or institutions or speakers or iron: debateteam_prefetch_queryset = DebateTeam.objects.select_related( 'team') if institutions: debateteam_prefetch_queryset = debateteam_prefetch_queryset.select_related( 'team__institution') if speakers: debateteam_prefetch_queryset = debateteam_prefetch_queryset.prefetch_related( Prefetch('team__speaker_set', queryset=Speaker.objects.order_by('name'))) if iron: debateteam_prefetch_queryset = debateteam_prefetch_queryset.annotate( iron=Count( 'speakerscore', filter=Q( speakerscore__ghost=True, speakerscore__ballot_submission__confirmed=True, ), distinct=True), iron_prev=Count( 'team__debateteam__speakerscore', filter=Q( team__debateteam__speakerscore__ghost=True, team__debateteam__speakerscore__ballot_submission__confirmed =True, team__debateteam__debate__round=self.prev, ), distinct=True), ) debates = debates.prefetch_related( Prefetch('debateteam_set', queryset=debateteam_prefetch_queryset)) if ordering: debates = debates.order_by(*ordering) # These functions populate relevant attributes of each debate, operating in-place if results: populate_confirmed_ballots(debates, motions=True, results=True) if wins: populate_wins(debates) if check_ins: populate_checkins(debates, self.tournament) return debates