Example #1
0
def capture_detail(request, pk):
    """
    Get, update or delete particular capture.
    """
    try:
        capture = Capture.objects.get(pk=pk)
    except Capture.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = CaptureSerializer(capture)
        return Response(serializer.data)
    
    elif request.method == 'PUT':
        serializer = CaptureSerializer(capture, data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        capture.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Example #2
0
def capture_list(request):
    """
    List all captures, or create new.
    """
    if request.method == 'GET':
        captures = Capture.objects.all()
        serializer = CaptureSerializer(captures)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = CaptureSerializer(data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST)