Exemple #1
0
    def post(self, request, format=None):
        """
        Method used to create and store a new VideoItem object with the provided data.

        @param request: HttpRequest containing the serialized data that will be used to create a new VideoItem object.
        @type request: HttpRequest
        @param format: The format used to serialize objects data, JSON by default.
        @type format: string
        @return: HttpResponse containing the id of the new created VideoItem object, error otherwise.
        @rtype: HttpResponse
        """
        request.data['owner'] = request.user.id
        serializer = VideoItemSerializer(data=request.data)
        if request.FILES and request.FILES['file'].content_type.split('/')[0] != 'video' :
            return Response('Content type not supported', status=status.HTTP_400_BAD_REQUEST)

        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)
Exemple #2
0
    def put(self, request, pk, format=None):
        """
        Method used to update stored information of a specific VideoItem object.
        The fresh data is provided in a serialized format.

        @param request: HttpRequest containing the updated VideoItem field data.
        @type request: HttpRequest
        @param pk: Primary key used to retrieve a VideoItem object.
        @type pk: int
        @param format: Format used for data serialization.
        @type format: string
        @return: HttpResponse containing all update object data.
        @rtype: HttpResponse
        """
        with edit_lock:
            item = self.get_object(pk, request.user)
            serializer = VideoItemSerializer(item, data=request.data, partial = True)
            if serializer.is_valid():
                serializer.save()
                return Response(serializer.data)
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)