コード例 #1
0
ファイル: player_api_view.py プロジェクト: pdhummel/clue
 def put(self, request, pk, format=None):
     player = self.get_object(pk)
     serializer = PlayerSerializer(player, data=request.DATA)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
ファイル: rest_apis.py プロジェクト: pdhummel/clue
def player_list(request, format=None):
    """
    List all players or create a new player.
    """
    if request.method == 'GET':
        players = Player.objects.all()
        serializer = PlayerSerializer(players, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = PlayerSerializer(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)
コード例 #3
0
ファイル: rest_apis.py プロジェクト: pdhummel/clue
def player_detail(request, pk, format=None):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        player = Player.objects.get(pk=pk)
    except Player.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = PlayerSerializer(player)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = PlayerSerializer(snippet, data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        player.delete()
        return HttpResponse(status=204)
コード例 #4
0
ファイル: player_api_view.py プロジェクト: pdhummel/clue
 def post(self, request, format=None):
     serializer = PlayerSerializer(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)