예제 #1
0
파일: views.py 프로젝트: crs4/ACTIVE
    def post(self, request, format=None):
        """
        Method used to create and save a new EntityModel object.
        The new object is returned in a serialized way.

        @param request: The HTTP request used to provide the EntityModel data.
        @type request: HttpRequest
        @return: A HTTP response containing the new EntityModel object seialized in a JSON format.
        @rtype: HttpResponse
        """
        serializer = EntityModelSerializer(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)
예제 #2
0
파일: views.py 프로젝트: crs4/ACTIVE
    def put(self, request, pk, format=None):
        """
        Method used to edit a specific EntityModel object.

        @param request: The HTTP request used to update a specific EntityModel object
        @type request: HttpRequest
        @param pk: The id of the EntityModel object that will be updated
        @type pk: int
        @return: The HTTP response containing the update EntityModel object
        @rtype: HttpResponse
        """
        with edit_lock:
            model = self.__get_object(pk)
            serializer = EntityModelSerializer(model, 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)