diff --git a/greg/api/views/sponsor.py b/greg/api/views/sponsor.py index 755ee5283af533331134252d39a8cffb9ec3c5f1..adb8cf21b380286036ef465bf4d4f04edb0304dc 100644 --- a/greg/api/views/sponsor.py +++ b/greg/api/views/sponsor.py @@ -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) diff --git a/greg/tests/api/test_sponsor.py b/greg/tests/api/test_sponsor.py index c0ae4d00c9088aa4a343a8050d8d24935188cc14..58d5f7b63e96621da83f7083747ccea28ce2dcc4 100644 --- a/greg/tests/api/test_sponsor.py +++ b/greg/tests/api/test_sponsor.py @@ -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