Exemplo n.º 1
0
Arquivo: views.py Projeto: crs4/ACTIVE
    def post(self, request, format=None):
        """
        Method used to create and save a new Instance object.
        The new object created is returned in a serialized way.

        @param request: The HTTP request containing the data for a new Instance object
        @type request: HttpRequest
        @return: The HTTP response containing the new Instance object
        @rtype: HttpResponse
        """
        serializer = InstanceSerializer(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)
Exemplo n.º 2
0
Arquivo: views.py Projeto: crs4/ACTIVE
    def put(self, request, pk, format=None):
        """
        Method used to edit a specific Instance object.

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