def get(self, request, pk): """ Retrieve, update or delete a document. """ document = self.get_object(pk) serializer = DocumentSerializer(document) return Response(serializer.data)
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)
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)
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)
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)
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)
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)
def get(self, request): documents = Document.objects.all() serializer = DocumentSerializer(documents, many=True) return Response(serializer.data)