예제 #1
0
 def post(self, request, pk=None, format=None):
     """增加队伍"""
     serializer = TeamSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #2
0
class TeamDetail(APIView):
    """
    Retrieve, update or delete a casting request of client.
    """
    def get_object(self, pk):
        try:
            return Team.objects.get(pk=pk)
        except Team.DoesNotExist:
            raise Http404

    @swagger_auto_schema(responses={200: TeamSerializer(many=False)})
    def get(self, request, pk, format=None):
        team = self.get_object(pk)
        serializer = TeamSerializer(team)
        return Response(serializer.data)

    @swagger_auto_schema(
        request_body=TeamCreateSerializer,
        responses={200: TeamSerializer(many=False)}
    )
    def put(self, request, pk, format=None):
        team = self.get_object(pk)
        serializer = TeamSerializer(team, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)

    @swagger_auto_schema(responses={200: 'OK'})
    def delete(self, request, pk, format=None):
        team = self.get_object(pk)
        team.delete()
        return Response({'id': int(pk)}, status=status.HTTP_200_OK)
예제 #3
0
 def put(self, request, pk, format=None):
     team = self.get_object(pk)
     serializer = TeamSerializer(team, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
예제 #4
0
 def put(self, request, pk, format=None):
     """修改队伍"""
     team = get_object_or_404(Team, pk=pk)
     serializer = TeamSerializer(team, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #5
0
 def get(self, request, pk=None, format=None):
     """查询队伍"""
     if pk is None:
         teams = Team.objects.all()
         serializer = TeamSerializer(teams, many=True)
     else:
         team = get_object_or_404(Team, pk=pk)
         serializer = TeamSerializer(team)
     return Response(serializer.data)
예제 #6
0
    def test_retrieve_teams_by_coach(self):
        """Test that coach can access only the team assigned to him/her"""



        team1 = create_team('Test T1', '*****@*****.**')
        team2 = create_team('Test T2', '*****@*****.**')

        player1 = create_player('P1', 45, team1)
        player2 = create_player('P1', 45, team1)

        team1.players.add(player1)
        team1.players.add(player2)

        self.client.force_authenticate(self.user_coach)
        res = self.client.get(TEAM_URL)

        teams = Team.objects.filter(coach='*****@*****.**')
        serializer = TeamSerializer(teams, many=True)

        print('res.data', res.data)
        print('res.data', res.data[0]['players'])
        print('serialized.data', serializer.data)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(len(res.data), 1)
        self.assertEqual(res.data, serializer.data)
예제 #7
0
class DcEntrySerializer(serializers.ModelSerializer):
    team = TeamSerializer(many=False, read_only=True)

    class Meta:
        model = DcEntry
        fields = ('team', 'score', 'team', 'score', 'baja_time', 'baja_score',
                  'toike_cannon_score', 'wise_score', 'hpv_score')
예제 #8
0
class TeamCreate(APIView):
    """
    Get current client info
    """
    # authentication_classes = (authentication.TokenAuthentication, )
    # permission_classes = (permissions.IsAuthenticated,)

    def get_object(self, user):
      try:
        user = User.objects.get(pk=user.pk)
        client = Client.objects.get(user=user.id)
        return client
      except Client.DoesNotExist:
        raise Http404

    @swagger_auto_schema(request_body=TeamCreateSerializer,
                         responses={200: TeamSerializer(many=False)})
    def post(self, request, format=None):
        client = self.get_object(request.user)
        serializer = TeamCreateSerializer(data=request.data)
        if serializer.is_valid():
            data = serializer.validated_data
            team_name = data['name'] if 'name' in data else ''
            new_team = Team.objects.create(
                client=client,
                name=team_name
            )
            new_team.save()
            new_serializer = TeamSerializer(new_team)
            return Response(new_serializer.data, status=status.HTTP_201_CREATED)
        return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
예제 #9
0
 def post(request):
     serializer = TeamSerializerCreate(validated_data=request.data,
                                       context={'request': request})
     if serializer.is_valid():
         serializer.save()
         return Response(TeamSerializer(serializer.instance).data,
                         status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #10
0
def serializeWithOwners(data):
    for division in data['divisions']:
        val = division['teams'].values()
        team_serialized = TeamSerializer(val, many=True)
        division['teams'] = team_serialized.data

    data = addOwners(data)
    return data
예제 #11
0
class ClientAllInfoSerializer(serializers.ModelSerializer):
    user = GeneralUserSerializer(many=False, read_only=True)
    casting_requests = CastingRequestSerializer(many=True, read_only=True)
    client_teams = TeamSerializer(many=True, read_only=True)

    class Meta:
        model = Client
        fields = ('id', 'user', 'created', 'casting_requests', 'client_teams')
class TeamMemberDetailSerializer(serializers.ModelSerializer):
    team = TeamSerializer(many=False, read_only=True)

    class Meta:
        model = TeamMember
        fields = ('id', 'team', 'member_email', 'created')

    def create(self, validated_data):
        return TeamMember.objects.create(**validated_data)
예제 #13
0
    def get(self, request, id):

        try:
            team = Team.objects.get(pk=id)
        except Team.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        team_serializer = TeamSerializer(team)
        return Response(team_serializer.data)
예제 #14
0
def league_settings(request, seasonId, leagueId):
    r = service.fetch('leagueSettings', leagueId, seasonId)
    data = r.json()

    val = data['leaguesettings']['teams'].values()
    team_serialized = TeamSerializer(val, many=True)
    data['leaguesettings']['teams'] = team_serialized.data
    status = r.status_code

    return Response(data, status)
예제 #15
0
class TeamList(APIView):
    """
    Retrieve all casting requests of client.
    """
    @swagger_auto_schema(responses={200: TeamSerializer(many=True)})
    def get(self, request, format=None):
        user = User.objects.get(pk=request.user.pk)
        client = Client.objects.get(user=user)
        teams = Team.objects.filter(client_id=client.id)
        serializer = TeamSerializer(teams, many=True)
        return Response(serializer.data)
예제 #16
0
 def post(self, request, format=None):
     client = self.get_object(request.user)
     serializer = TeamCreateSerializer(data=request.data)
     if serializer.is_valid():
         data = serializer.validated_data
         team_name = data['name'] if 'name' in data else ''
         new_team = Team.objects.create(client=client, name=team_name)
         new_team.save()
         new_serializer = TeamSerializer(new_team)
         return Response(new_serializer.data,
                         status=status.HTTP_201_CREATED)
     return Response({'error': serializer.errors},
                     status=status.HTTP_400_BAD_REQUEST)
예제 #17
0
    def test_retrieve_teams_by_admin(self):
        """Test that admin can access all teams data"""
        create_team('Test T1', '*****@*****.**')
        create_team('Test T2', '*****@*****.**')

        self.client.force_authenticate(self.user_admin)
        res = self.client.get(TEAM_URL)

        teams = Team.objects.all();
        serializer = TeamSerializer(teams, many=True)

        # print('res.data', res.data)
        # print('serialized.data', serializer.data)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(len(res.data), 2)
        self.assertEqual(res.data, serializer.data)
예제 #18
0
 def get(request):
     teams = Team.objects.all()
     return Response(TeamSerializer(teams, many=True).data)
예제 #19
0
class GameSerializer(serializers.ModelSerializer):
    winner = TeamSerializer()

    class Meta:
        model = Game
        fields = ('name', 'winner', 'id', 'date')
예제 #20
0
 def get(self, request, pk, format=None):
     team = self.get_object(pk)
     serializer = TeamSerializer(team)
     return Response(serializer.data)
예제 #21
0
 def get(self, request, format=None):
     user = User.objects.get(pk=request.user.pk)
     client = Client.objects.get(user=user)
     teams = Team.objects.filter(client_id=client.id)
     serializer = TeamSerializer(teams, many=True)
     return Response(serializer.data)
예제 #22
0
class BmEntrySerializer(serializers.ModelSerializer):
    team = TeamSerializer(many=False, read_only=True)

    class Meta:
        model = BmEntry
        fields = ('team', 'score')
예제 #23
0
    def get(self, request):
        teams = Team.objects.all().order_by("name")

        team_serializer = TeamSerializer(teams, many=True)
        return Response(team_serializer.data)
예제 #24
0
파일: views.py 프로젝트: wkdwogns/soccer
 def get_myTeam(self, requests):
     pk = requests.user.pk
     rs = List.objects.filter(creId=pk)
     serializer = TeamSerializer(rs, many=True)
     return Response(serializer.data)