(backend) allow forcing page size within limits

We want to be able to increase the page size with by passing
the query string parameter "page_size".
This commit is contained in:
Samuel Paccoud - DINUM
2025-02-15 13:16:35 +01:00
committed by Manuel Raynaud
parent 757d7f35cd
commit fcf8b38021
3 changed files with 31 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ and this project adheres to
## Added
- ✨(backend) allow forcing page size within limits
- 💄(frontend) add error pages #643
- 🔒️ Manage unsafe attachments #663
- ✨(frontend) Custom block quote with export #646

View File

@@ -418,6 +418,7 @@ class DocumentViewSet(
metadata_class = DocumentMetadata
ordering = ["-updated_at"]
ordering_fields = ["created_at", "updated_at", "title"]
pagination_class = Pagination
permission_classes = [
permissions.DocumentAccessPermission,
]

View File

@@ -328,6 +328,35 @@ def test_api_documents_list_pagination(
assert document_ids == []
def test_api_documents_list_pagination_force_page_size():
"""Page size can be set via querystring."""
user = factories.UserFactory()
client = APIClient()
client.force_login(user)
document_ids = [
str(access.document_id)
for access in factories.UserDocumentAccessFactory.create_batch(3, user=user)
]
# Force page size
response = client.get(
"/api/v1.0/documents/?page_size=2",
)
assert response.status_code == 200
content = response.json()
assert content["count"] == 3
assert content["next"] == "http://testserver/api/v1.0/documents/?page=2&page_size=2"
assert content["previous"] is None
assert len(content["results"]) == 2
for item in content["results"]:
document_ids.remove(item["id"])
def test_api_documents_list_authenticated_distinct():
"""A document with several related users should only be listed once."""
user = factories.UserFactory()