mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Add "all" property to results
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.auth.models import User
|
||||
@@ -9,6 +10,7 @@ from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.filters import OrderingFilter
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from documents.permissions import PaperlessObjectPermissions
|
||||
@@ -23,6 +25,47 @@ class StandardPagination(PageNumberPagination):
|
||||
page_size_query_param = "page_size"
|
||||
max_page_size = 100000
|
||||
|
||||
def get_paginated_response(self, data):
|
||||
return Response(
|
||||
OrderedDict(
|
||||
[
|
||||
("count", self.page.paginator.count),
|
||||
("next", self.get_next_link()),
|
||||
("previous", self.get_previous_link()),
|
||||
("all", self.get_all_result_ids()),
|
||||
("results", data),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
def get_all_result_ids(self):
|
||||
ids = []
|
||||
if hasattr(self.page.paginator.object_list, "saved_results"):
|
||||
results_page = self.page.paginator.object_list.saved_results[0]
|
||||
if results_page is not None:
|
||||
for i in range(0, len(results_page.results.docs())):
|
||||
try:
|
||||
fields = results_page.results.fields(i)
|
||||
if "id" in fields:
|
||||
ids.append(fields["id"])
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
for obj in self.page.paginator.object_list:
|
||||
if hasattr(obj, "id"):
|
||||
ids.append(obj.id)
|
||||
elif hasattr(obj, "fields"):
|
||||
ids.append(obj.fields()["id"])
|
||||
return ids
|
||||
|
||||
def get_paginated_response_schema(self, schema):
|
||||
response_schema = super().get_paginated_response_schema(schema)
|
||||
response_schema["properties"]["all"] = {
|
||||
"type": "array",
|
||||
"example": "[1, 2, 3]",
|
||||
}
|
||||
return response_schema
|
||||
|
||||
|
||||
class FaviconView(View):
|
||||
def get(self, request, *args, **kwargs): # pragma: nocover
|
||||
|
Reference in New Issue
Block a user