From 50c0c65c60cb4254fcfe02782f061e58d219ac5f Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Fri, 30 Dec 2022 13:43:49 -0800 Subject: [PATCH] Updates the post view to return the async task id. Adds query parameter to the tasks endpoint to get single task status --- src/documents/views.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/documents/views.py b/src/documents/views.py index 7ff6e90d9..e313ae17e 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -617,7 +617,7 @@ class PostDocumentView(GenericAPIView): task_id = str(uuid.uuid4()) - consume_file.delay( + async_task = consume_file.delay( temp_filename, override_filename=doc_name, override_title=title, @@ -628,7 +628,7 @@ class PostDocumentView(GenericAPIView): override_created=created, ) - return Response("OK") + return Response(async_task.id) class SelectionDataView(GenericAPIView): @@ -886,13 +886,18 @@ class TasksViewSet(ReadOnlyModelViewSet): permission_classes = (IsAuthenticated,) serializer_class = TasksViewSerializer - queryset = ( - PaperlessTask.objects.filter( - acknowledged=False, + def get_queryset(self): + queryset = ( + PaperlessTask.objects.filter( + acknowledged=False, + ) + .order_by("date_created") + .reverse() ) - .order_by("date_created") - .reverse() - ) + task_id = self.request.query_params.get("task_id") + if task_id is not None: + queryset = PaperlessTask.objects.filter(task_id=task_id) + return queryset class AcknowledgeTasksView(GenericAPIView):