Skip to content
Snippets Groups Projects
Verified Commit 75740d97 authored by Marte Fossum's avatar Marte Fossum
Browse files

Add pagination to list-sponsororgunits

parent cdef42c9
No related branches found
No related tags found
1 merge request!397Add pagination to list-sponsororgunits
Pipeline #187486 passed
......@@ -69,6 +69,7 @@ class SponsorOrgunitLinkView(
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.DestroyModelMixin,
mixins.ListModelMixin,
GenericViewSet,
):
"""Endpoint that allows manipulation of links between a sponsor and the units he is attached to"""
......@@ -126,6 +127,10 @@ class SponsorOrgunitLinkView(
"""Lists all SponsorOrganizationalUnit objects connected to the sponsor"""
sponsor_id = kwargs["sponsor_id"]
all_units = self.queryset.filter(sponsor__id=sponsor_id).all()
page = self.paginate_queryset(all_units)
if page is not None:
serializer = self.serializer_class(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.serializer_class(all_units, many=True)
return Response(serializer.data)
......
......@@ -233,7 +233,7 @@ def test_list_all_sponsor_orgunits(
):
url = reverse("v1:sponsor_orgunit-list", kwargs={"sponsor_id": sponsor_guy.id})
sponsor_units = client.get(url).json()
sponsor_units = client.get(url).json()["results"]
assert len(sponsor_units) == 2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment