示例#1
0
    def get(self, request, pk):
        """
        Retrieve, update or delete a document.
        """
        document = self.get_object(pk)

        serializer = DocumentSerializer(document)

        return Response(serializer.data)
示例#2
0
    def put(self, request, pk):
        data = JSONParser().parse(request)
        document = self.get_object(pk)

        serializer = DocumentSerializer(document, data=data)

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#3
0
    def get(self, request, pk):
        """
        Retrieve, update or delete a document.
        """
        document = self.get_object(pk)

        if request.user.has_perm(Access.PERM_READ, document):
            serializer = DocumentSerializer(document)
            return Response(serializer.data)

        return Response(status=status.HTTP_403_FORBIDDEN)
示例#4
0
文件: api.py 项目: vi-n/papermerge
    def put(self, request, filename):
        file_obj = request.data['file']

        doc = Document.import_file(file_obj.temporary_file_path(),
                                   username=request.user.username,
                                   file_title=filename)

        if isinstance(doc, Document):
            serializer = DocumentSerializer(doc)
            return Response(serializer.data)

        return Response(status=200)
示例#5
0
    def put(self, request, pk):
        data = JSONParser().parse(request)
        document = self.get_object(pk)

        if request.user.has_perm(Access.PERM_WRITE, document):
            serializer = DocumentSerializer(document, data=data)

            if serializer.is_valid():
                serializer.save()
                return Response(serializer.data)

        return Response(status=status.HTTP_403_FORBIDDEN)
示例#6
0
    def put(self, request, filename):
        file_obj = request.data['file']
        imp = DocumentImporter(
            file=file_obj.temporary_file_path(),
            username=request.user.username,
        )
        doc = imp.import_file(file_title=filename,
                              apply_async=True,
                              delete_after_import=False)
        if isinstance(doc, Document):
            serializer = DocumentSerializer(doc)
            return Response(serializer.data)

        return Response(status=200)
示例#7
0
    def put(self, request, filename):
        file_obj = request.data['file']
        init_kwargs = {'payload': file_obj, 'processor': WEB}

        apply_kwargs = {
            'user': request.user.username,
            'name': filename,
            'apply_async': True
        }

        doc = go_through_pipelines(init_kwargs=init_kwargs,
                                   apply_kwargs=apply_kwargs)

        if isinstance(doc, Document):
            serializer = DocumentSerializer(doc)
            return Response(serializer.data)

        return Response(status=200)
示例#8
0
    def get(self, request):
        documents = Document.objects.all()
        serializer = DocumentSerializer(documents, many=True)

        return Response(serializer.data)