Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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)
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
    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
Пример #9
0
    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