Esempio n. 1
0
    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)
Esempio n. 2
0
    def get_ballots_dicts(self):
        draw = self.round.debate_set_with_prefetches()

        # Create the DebateIdentifiers for the ballots if needed
        create_identifiers(DebateIdentifier, draw)
        identifiers = DebateIdentifier.objects.values('debate_id', 'barcode')

        draw = sorted(draw, key=lambda d: d.venue.display_name if d.venue else "")
        ballots_dicts = []

        # Force translation before JSON serialization
        sides_and_positions = [(side, [str(pos) for pos in positions])
            for side, positions in side_and_position_names(self.tournament)]

        for debate in draw:
            debate_dict = {}

            if debate.venue:
                debate_dict['venue'] = {'display_name': debate.venue.display_name}
            else:
                debate_dict['venue'] = None

            debate_dict['barcode'] = next((i['barcode'] for i in identifiers if i['debate_id'] == debate.id), None)

            debate_dict['debateTeams'] = []
            for side, (side_name, positions) in zip(self.tournament.sides, sides_and_positions):
                dt_dict = {'side_name': side_name, 'positions': positions}
                try:
                    team = debate.get_team(side)
                    dt_dict['team'] = {
                        'short_name': team.short_name,
                        'code_name': team.code_name,
                        'speakers': [{'name': s.name} for s in team.speakers],
                    }
                except DebateTeam.DoesNotExist:
                    dt_dict['team'] = None
                debate_dict['debateTeams'].append(dt_dict)

            debate_dict['debateAdjudicators'] = []
            for adj, pos in debate.adjudicators.with_positions():
                da_dict = {'position': pos}
                da_dict['adjudicator'] = {
                    'name': adj.name,
                    'institution': {'code': adj.institution.code if adj.institution else _("Unaffiliated")},
                }
                debate_dict['debateAdjudicators'].append(da_dict)

            if self.round.ballots_per_debate == 'per-adj':
                authors = list(debate.adjudicators.voting_with_positions())
            else:
                authors = [(debate.adjudicators.chair, debate.adjudicators.POSITION_CHAIR)]

            blank_author_dict = {
                'author': "_______________________________________________",
                'authorInstitution': "",
                'authorPosition': "",
            }

            # Add a ballot for each author
            for author, pos in authors:
                if author:
                    ballot_dict = {
                        'author': author.name,
                        'authorInstitution': author.institution.code if author.institution else _("Unaffiliated"),
                        'authorPosition': pos,
                    }
                else:
                    ballot_dict = blank_author_dict

                ballot_dict.update(debate_dict)
                ballots_dicts.append(ballot_dict)

            if len(authors) == 0:
                ballot_dict = blank_author_dict
                ballot_dict.update(debate_dict)
                ballots_dicts.append(ballot_dict)

        return ballots_dicts
Esempio n. 3
0
    def get_ballots_dicts(self):
        draw = self.round.debate_set_with_prefetches(iron=True)

        # Create the DebateIdentifiers for the ballots if needed
        create_identifiers(DebateIdentifier, draw)
        identifiers = DebateIdentifier.objects.values('debate_id', 'barcode')

        draw = sorted(draw,
                      key=lambda d: d.venue.display_name if d.venue else "")
        ballots_dicts = []

        # Force translation before JSON serialization
        sides_and_positions = [
            (side, [str(pos) for pos in positions])
            for side, positions in side_and_position_names(self.tournament)
        ]

        for debate in draw:
            debate_dict = {}

            if debate.venue:
                debate_dict['venue'] = {
                    'display_name': debate.venue.display_name
                }
            else:
                debate_dict['venue'] = None

            debate_dict['barcode'] = next(
                (i['barcode']
                 for i in identifiers if i['debate_id'] == debate.id), None)

            debate_dict['debateTeams'] = []
            for side, (side_name, positions) in zip(self.tournament.sides,
                                                    sides_and_positions):
                dt_dict = {'side_name': side_name, 'positions': positions}
                try:
                    team = debate.get_team(side)
                    dt_dict['team'] = {
                        'short_name': team.short_name,
                        'code_name': team.code_name,
                        'speakers': [{
                            'name': s.name
                        } for s in team.speakers],
                        'iron': debate.get_dt(side).iron_prev > 0,
                    }
                except DebateTeam.DoesNotExist:
                    dt_dict['team'] = None
                debate_dict['debateTeams'].append(dt_dict)

            debate_dict['debateAdjudicators'] = []
            for adj, pos in debate.adjudicators.with_positions():
                da_dict = {'position': pos}
                da_dict['adjudicator'] = {
                    'name': adj.name,
                    'institution': {
                        'code':
                        adj.institution.code
                        if adj.institution else _("Unaffiliated")
                    },
                }
                debate_dict['debateAdjudicators'].append(da_dict)

            if self.round.ballots_per_debate == 'per-adj':
                authors = list(debate.adjudicators.voting_with_positions())
            else:
                authors = [(debate.adjudicators.chair,
                            debate.adjudicators.POSITION_CHAIR)]

            blank_author_dict = {
                'author': "_______________________________________________",
                'authorInstitution': "",
                'authorPosition': "",
            }

            # Add a ballot for each author
            for author, pos in authors:
                if author:
                    ballot_dict = {
                        'author':
                        author.name,
                        'authorInstitution':
                        author.institution.code
                        if author.institution else _("Unaffiliated"),
                        'authorPosition':
                        pos,
                    }
                else:
                    ballot_dict = blank_author_dict

                ballot_dict.update(debate_dict)
                ballots_dicts.append(ballot_dict)

            if len(authors) == 0:
                ballot_dict = blank_author_dict
                ballot_dict.update(debate_dict)
                ballots_dicts.append(ballot_dict)

        return ballots_dicts