コード例 #1
0
 def post(self, request, *args, **kwargs):
     """Creates an identifier"""
     obj = self.get_object_queryset()  # Don't .get() as create_identifiers expects a queryset
     if not obj.exists():
         raise Http404
     create_identifiers(self.model.checkin_identifier.related.related_model, obj)
     return Response(self.get_response_dict(request, obj.get(), False))
コード例 #2
0
ファイル: views.py プロジェクト: tienne-B/tabbycat
 def post(self, request, *args, **kwargs):
     """Creates an identifier"""
     obj = self.get_object_queryset(
     )  # Don't .get() as create_identifiers expects a queryset
     if not obj.exists():
         raise NotFound("Object could not be found")
     status = 200 if hasattr(obj, 'checkin_identifier') else 201
     create_identifiers(self.model.checkin_identifier.related.related_model,
                        obj)
     return Response(self.get_response_dict(request, obj.get(), False,
                                            None),
                     status=status)
コード例 #3
0
ファイル: views.py プロジェクト: czlee/tabbycat
    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
コード例 #4
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