コード例 #1
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)
コード例 #2
0
ファイル: views.py プロジェクト: pmutua/elite-schedule
 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)
コード例 #3
0
ファイル: views.py プロジェクト: pmutua/elite-schedule
 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
コード例 #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')
コード例 #5
0
ファイル: views.py プロジェクト: pmutua/elite-schedule
    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)
コード例 #6
0
ファイル: views.py プロジェクト: pmutua/elite-schedule
 def list(self, request):
     queryset = Match.objects.all()
     serializer = MatchSerializer(queryset, many=True)
     return Response(serializer.data)