Beispiel #1
0
def create_match(request):
    serializer = MatchSerializer(data=request.DATA)
    json_response = simplejson.loads(JSONRenderer().render(serializer.data))
    match = get_match_object(json_response['user_id'],json_response['match_user_id'])
    if match!=None:
        serializer = MatchSerializer(match, data=request.DATA)
    if serializer.is_valid():
        serializer.save()
        return Response(serializer.data, status=status.HTTP_200_OK)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
 def list(self,request):
     queryset = Match.objects.filter(
         Q(division__icontains="I1")|
         Q(division__icontains="I2")
         )
     serializer = MatchSerializer(queryset, many=True)
     return Response(serializer.data)
Beispiel #3
0
 def post(self, request):
     serializer = MatchSerializer(data=request.DATA)
     if serializer.is_valid():
         try:
             match = serializer.object
             for match_user in [match.loser, match.winner]:
                 # Ranking objects are created automatically when users are.
                 # It should never be the case that a user does not have an
                 # asscoiated ranking object.
                 user_ranking = Ranking.objects.get(player=match_user)
                 user_ranking.save(match=match)
                 if match_user == request.user:
                     updated_ranking = RankingSerializer(user_ranking, context={'request': request})
             return Response(updated_ranking.data, status=status.HTTP_200_OK)
         except IntegrityError:
             return Response({"msg": "User does not exist."}, status=status.HTTP_400_BAD_REQUEST)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #4
0
 def test_get_item(self):
     match_id = 9
     match = Match.objects.get(pk=match_id)
     request = factory.get('/api/teams/{0}/matches/{1}/'.format(
         self.dev_team.id, match_id))
     force_authenticate(request, user=self.admin_user)
     view = MatchViewSet.as_view({'get': 'retrieve'})
     response = view(request,
                     parent_lookup_team=str(self.dev_team.id),
                     pk=str(match_id))
     response.render()
     expected_data = MatchSerializer(match).data
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      'expected HTTP 200')
     for rk, ek in zip(response.data.keys(), expected_data.keys()):
         self.assertEqual(str(response.data[rk]), str(expected_data[ek]),
                          'expected correct match data')
Beispiel #5
0
 def get_queryset(self, *args, **kwargs):
     queryset_list = Match.objects.filter(
         id__gte=0)
     query = self.request.GET.get("q")
     if query:
         queryset_list = queryset_list.filter(
             Q(home_team__icontains=query)|
             Q(away_team__icontains=query)
         ).distinct()
     serializer =MatchSerializer(queryset_list, many=True)
     
     return queryset_list
Beispiel #6
0
def matches(request):
    if request.method == 'GET':
        serializer = MatchSerializer(Match.objects.all(), many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = MatchSerializer(data=request.data)
        if serializer.is_valid():
            match = serializer.save()
            return Response({"match_id": match.pk},
                            status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #7
0
    def serie_b(self, request):
        """
            Show all Serie B matches.
            
            ----
            Returns json data about a list of matches from Serie B Division.
            =======================================

            * **URL**

                /italy/serie_b

            * **Method:**

                `GET`
                
            *  **URL Params**

                None

            * **Data Params**

                None

            * **Error Response:**

                * **Code:** 404 NOT FOUND <br />
                **Content:** `{ error : "Matches doesn't exist" }`

                OR

                * **Code:** 401 UNAUTHORIZED <br />
                **Content:** `{ error : "You are unauthorized to make this request." }`

            * **Sample Call:**

                ```bash
                curl -H "Authorization: JWT <your_token>" -H "Content-Type: application/json" http://localhost:8000/api/elite_schedule/italy/serie_b/

                ```

        """
        matches = Match.objects.serie_b()
        serializer = MatchSerializer(matches, many=True)
        return Response(serializer.data)
Beispiel #8
0
 def list(self, request):
     queryset = Match.objects.all()
     serializer = MatchSerializer(queryset, many=True)
     return Response(serializer.data)