Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        kwargs['ballotsub'] = self.ballotsub
        kwargs['debate'] = self.debate
        kwargs['all_ballotsubs'] = self.get_all_ballotsubs()
        kwargs['new'] = self.relates_to_new_ballotsub
        kwargs['for_admin'] = self.for_admin

        use_team_code_names = use_team_code_names_data_entry(self.tournament, self.tabroom)
        kwargs['use_team_code_names'] = use_team_code_names

        sides = self.tournament.sides
        if use_team_code_names == 'off':
            kwargs['debate_name'] = _(" vs ").join(self.debate.get_team(side).short_name for side in sides)
        else:
            kwargs['debate_name'] = _(" vs ").join(self.debate.get_team(side).code_name for side in sides)
        kwargs['page_subtitle'] = _("%(round)s @ %(room)s") % {
            'round': self.debate.round.name,
            'room': getattr(self.debate.venue, 'display_name', _("N/A")),
        }

        kwargs['iron'] = self.debate.debateteam_set.annotate(iron=Count('team__debateteam__speakerscore',
            filter=Q(team__debateteam__debate__round=self.debate.round.prev) & Q(team__debateteam__speakerscore__ghost=True),
            distinct=True)).filter(iron__gt=0)
        kwargs['currentIron'] = self.debate.debateteam_set.annotate(iron=Count('team__debateteam__speakerscore',
            filter=Q(team__debateteam__debate__round=self.debate.round) & Q(team__debateteam__speakerscore__ghost=True),
            distinct=True)).filter(iron__gt=0)

        return super().get_context_data(**kwargs)
Exemplo n.º 2
0
    def broadcast_checkin(self, event):
        content = event['content']
        barcode_ids = [b for b in content['barcodes'] if b is not None]
        return_content = {
            'created': content['status'],
            'checkins': [],
            'component_id': content['component_id']
        }

        use_team_code_names = use_team_code_names_data_entry(
            self.tournament, True)

        for barcode in barcode_ids:
            try:
                identifier = Identifier.objects.get(barcode=barcode)
                if content['status'] is True:
                    # If checking-in someone
                    checkin = Event.objects.create(identifier=identifier,
                                                   tournament=self.tournament)
                    checkin_dict = checkin.serialize()

                    if hasattr(identifier.owner, 'matchup'):
                        if use_team_code_names:
                            checkin_dict[
                                'owner_name'] = identifier.owner.matchup_codes
                        else:
                            checkin_dict[
                                'owner_name'] = identifier.owner.matchup
                    else:
                        checkin_dict['owner_name'] = identifier.owner.name

                    return_content['checkins'].append(checkin_dict)
                else:
                    # If undoing/revoking a check-in
                    if content['type'] == 'people':
                        window = 'checkin_window_people'
                    else:
                        window = 'checkin_window_venues'

                    checkins = get_unexpired_checkins(self.tournament, window)
                    checkins.filter(identifier=identifier).delete()
                    return_content['checkins'].append({'identifier': barcode})

            except ObjectDoesNotExist:
                # Only raise an error for single check-ins as for multi-check-in
                # events via the status page its clear what has failed or not
                if len(barcode_ids) == 1:
                    msg = _("Sent checkin identifier doesn't exist")
                    self.send_error(_("Checkins"), msg, content)
                    return

        if len(return_content['checkins']
               ) == 0 and content['status'] is not False:
            msg = _("No checkin identifiers exist for sent barcodes")
            self.send_error(_("Checkins"), msg, content)
            return

        self.send_json(return_content)
Exemplo n.º 3
0
 def matchup_description(self):
     """This is primarily shown in messages, some of which are public. This
     is slightly different to its use in templates, but should match given
     paper ballots use code names. It does however ignore the 'both' option
     in favour of just showing the code name"""
     code_opt = use_team_code_names_data_entry(self.tournament, self.tabroom)
     if code_opt == 'code' or code_opt == 'both':
         return self.debate.matchup_codes
     else:
         return self.debate.matchup
Exemplo n.º 4
0
 def matchup_description(self):
     """This is primarily shown in messages, some of which are public. This
     is slightly different to its use in templates, but should match given
     paper ballots use code names. It does however ignore the 'both' option
     in favour of just showing the code name"""
     code_opt = use_team_code_names_data_entry(self.tournament, self.tabroom)
     if code_opt == 'code' or code_opt == 'both':
         return self.debate.matchup_codes
     else:
         return self.debate.matchup
Exemplo n.º 5
0
    def get_tables(self):
        tournament = self.tournament

        use_code_names = use_team_code_names_data_entry(
            self.tournament, self.tabroom)
        teams_table = TabbycatTableBuilder(view=self,
                                           sort_key="team",
                                           title=_("A Team"))
        add_link_data = [{
            'text': team_name_for_data_entry(team, use_code_names),
            'link': self.get_from_team_link(team),
        } for team in tournament.team_set.all()]
        header = {'key': 'team', 'title': _("Team")}
        teams_table.add_column(header, add_link_data)

        if tournament.pref('show_team_institutions'):
            teams_table.add_column(
                {
                    'key': 'institution',
                    'icon': 'home',
                    'tooltip': _("Institution"),
                }, [
                    team.institution.code
                    if team.institution else TabbycatTableBuilder.BLANK_TEXT
                    for team in tournament.team_set.all()
                ])

        adjudicators = tournament.adjudicator_set.all()

        adjs_table = TabbycatTableBuilder(view=self,
                                          sort_key="adjudicator",
                                          title=_("An Adjudicator"))
        adjudicators = tournament.adjudicator_set.all()

        add_link_data = [{
            'text': adj.name,
            'link': self.get_from_adj_link(adj),
        } for adj in adjudicators]
        header = {'key': 'adjudicator', 'title': _("Adjudicator")}
        adjs_table.add_column(header, add_link_data)

        if tournament.pref('show_adjudicator_institutions'):
            adjs_table.add_column(
                {
                    'key': 'institution',
                    'icon': 'home',
                    'tooltip': _("Institution"),
                }, [
                    adj.institution.code
                    if adj.institution else TabbycatTableBuilder.BLANK_TEXT
                    for adj in adjudicators
                ])

        return [teams_table, adjs_table]
Exemplo n.º 6
0
 def get_irons_list(self):
     iron_speeches = []
     use_code_names = use_team_code_names_data_entry(self.tournament, True)
     for d in self._get_draw():
         for side in self.tournament.sides:
             debateteam = d.get_dt(side)
             if debateteam.iron > 0 or debateteam.iron_prev:
                 iron_speeches.append({
                     'venue': d.venue.display_name if d.venue else None,
                     'team': team_name_for_data_entry(debateteam.team, use_code_names),
                     'current_round': debateteam.iron,
                     'previous_round': debateteam.iron_prev,
                 })
     return iron_speeches
Exemplo n.º 7
0
    def get_context_data(self, **kwargs):
        kwargs['ballotsub'] = self.ballotsub
        kwargs['debate'] = self.debate
        kwargs['all_ballotsubs'] = self.get_all_ballotsubs()
        kwargs['new'] = self.relates_to_new_ballotsub

        use_team_code_names = use_team_code_names_data_entry(self.tournament, self.tabroom)
        kwargs['use_team_code_names'] = use_team_code_names

        sides = self.tournament.sides
        if use_team_code_names == 'off':
            kwargs['debate_name'] = _(" vs ").join(self.debate.get_team(side).short_name for side in sides)
        else:
            kwargs['debate_name'] = _(" vs ").join(self.debate.get_team(side).code_name for side in sides)

        return super().get_context_data(**kwargs)
Exemplo n.º 8
0
    def get_tables(self):
        tournament = self.tournament

        use_code_names = use_team_code_names_data_entry(self.tournament, self.tabroom)
        teams_table = TabbycatTableBuilder(view=self, sort_key="team", title=_("A Team"))
        add_link_data = [{
            'text': team_name_for_data_entry(team, use_code_names),
            'link': self.get_from_team_link(team)
        } for team in tournament.team_set.all()]
        header = {'key': 'team', 'title': _("Team")}
        teams_table.add_column(header, add_link_data)

        if tournament.pref('show_team_institutions'):
            teams_table.add_column({
                'key': 'institution',
                'icon': 'home',
                'tooltip': _("Institution"),
            }, [team.institution.code if team.institution else TabbycatTableBuilder.BLANK_TEXT for team in tournament.team_set.all()])

        if tournament.pref('share_adjs'):
            adjudicators = Adjudicator.objects.filter(Q(tournament=tournament) | Q(tournament__isnull=True))
        else:
            adjudicators = tournament.adjudicator_set.all()

        adjs_table = TabbycatTableBuilder(view=self, sort_key="adjudicator", title=_("An Adjudicator"))
        if tournament.pref('share_adjs'):
            adjudicators = Adjudicator.objects.filter(Q(tournament=tournament) | Q(tournament__isnull=True))
        else:
            adjudicators = tournament.adjudicator_set.all()

        add_link_data = [{
            'text': adj.name,
            'link': self.get_from_adj_link(adj),
        } for adj in adjudicators]
        header = {'key': 'adjudicator', 'title': _("Adjudicator")}
        adjs_table.add_column(header, add_link_data)

        if tournament.pref('show_adjudicator_institutions'):
            adjs_table.add_column({
                'key': 'institution',
                'icon': 'home',
                'tooltip': _("Institution"),
            }, [adj.institution.code if adj.institution else TabbycatTableBuilder.BLANK_TEXT for adj in adjudicators])

        return [teams_table, adjs_table]
Exemplo n.º 9
0
    def get_context_data(self, **kwargs):
        kwargs['ballotsub'] = self.ballotsub
        kwargs['debate'] = self.debate
        kwargs['all_ballotsubs'] = self.get_all_ballotsubs()
        kwargs['new'] = self.relates_to_new_ballotsub

        use_team_code_names = use_team_code_names_data_entry(
            self.tournament, self.tabroom)
        kwargs['use_team_code_names'] = use_team_code_names

        sides = self.tournament.sides
        if use_team_code_names == 'off':
            kwargs['debate_name'] = _(" vs ").join(
                self.debate.get_team(side).short_name for side in sides)
        else:
            kwargs['debate_name'] = _(" vs ").join(
                self.debate.get_team(side).code_name for side in sides)

        return super().get_context_data(**kwargs)
Exemplo n.º 10
0
 def get_team_short_name(self, team):
     use_code_names = use_team_code_names_data_entry(self.tournament,
                                                     tabroom=True)
     return team_name_for_data_entry(team, use_code_names)
Exemplo n.º 11
0
    def populate_objects(self, prefill=True):
        super().populate_objects()
        use_code_names = use_team_code_names_data_entry(self.tournament, True)
        self.round = self.debate.round

        bses = BallotSubmission.objects.filter(
            debate=self.debate,
            participant_submitter__isnull=False,
            discarded=False,
            single_adj=True,
        ).distinct('participant_submitter').select_related(
            'participant_submitter').order_by('participant_submitter',
                                              '-version')
        populate_results(bses, self.tournament)
        self.merged_ballots = bses

        # Handle result conflicts
        self.result = DebateResult(self.ballotsub, tournament=self.tournament)
        try:
            self.result.populate_from_merge(*[b.result for b in bses])
        except ResultError as e:
            msg, t, adj, bs, side, speaker = e.args
            args = {
                'ballot_url':
                reverse_tournament(self.edit_ballot_url,
                                   self.tournament,
                                   kwargs={'pk': bs.id}),
                'adjudicator':
                adj.name,
                'speaker':
                speaker.name,
                'team':
                team_name_for_data_entry(self.debate.get_team(side),
                                         use_code_names),
            }
            if t == 'speaker':
                msg = _(
                    "The speaking order in the ballots is inconsistent, so could not be merged."
                )
            elif t == 'ghost':
                msg = _(
                    "Duplicate speeches are marked inconsistently, so could not be merged."
                )
            msg += _(
                " This error was caught in <a href='%(ballot_url)s'>%(adjudicator)s's ballot</a> for %(speaker)s (%(team)s)."
            )
            messages.error(self.request, msg % args)
            return HttpResponseRedirect(self.get_list_url())

        # Handle motion conflicts
        bs_motions = BallotSubmission.objects.filter(
            id__in=[b.id for b in bses],
            motion__isnull=False,
        ).prefetch_related('debateteammotionpreference_set__debate_team')
        if self.tournament.pref('enable_motions'):
            try:
                merge_motions(self.ballotsub, bs_motions)
            except ValidationError as e:
                messages.error(self.request, e)
                return HttpResponseRedirect(self.get_list_url())

        # Vetos
        try:
            self.vetos = merge_motion_vetos(self.ballotsub, bs_motions)
        except ValidationError as e:
            messages.error(self.request, e)
            return HttpResponseRedirect(self.get_list_url())
Exemplo n.º 12
0
 def get_team_short_name(self, team):
     use_code_names = use_team_code_names_data_entry(self.tournament, tabroom=True)
     return team_name_for_data_entry(team, use_code_names)