示例#1
0
    def post(self, request):
        """
        Creates a new Allocation
        """
        data = request.DATA
        serializer = AllocationSerializer(data=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
    def post(self, request):
        """
        Creates a new Allocation
        """
        data = request.data
        serializer = AllocationSerializer(data=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
    def patch(self, request, quota_id):
        """
        Partially updates the specified Allocation
        """
        data = request.DATA
        allocation = get_object_or_404(Allocation, id=quota_id)
        serializer = AllocationSerializer(allocation, data=data, partial=True)

        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)
示例#4
0
    def patch(self, request, quota_id):
        """
        Partially updates the specified Allocation
        """
        data = request.data
        allocation = get_object_or_404(Allocation, id=quota_id)
        serializer = AllocationSerializer(allocation, data=data, partial=True)

        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)
示例#5
0
 def get(self, request, allocation_id):
     """
     Fetch the specified Allocation
     """
     allocation = get_object_or_404(Allocation, id=allocation_id)
     serialized_data = AllocationSerializer(allocation).data
     return Response(serialized_data)
示例#6
0
 def get(self, request):
     """
     Returns a list of all existing Allocations
     """
     quotas = Allocation.objects.all()
     serialized_data = AllocationSerializer(quotas, many=True).data
     return Response(serialized_data)