Fixed #295: broken pagination in Subsonic API
This commit is contained in:
parent
4c81de9226
commit
031784556f
|
@ -208,7 +208,9 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
methods=["get", "post"], url_name="get_album_list2", url_path="getAlbumList2"
|
||||
)
|
||||
def get_album_list2(self, request, *args, **kwargs):
|
||||
queryset = music_models.Album.objects.with_tracks_count()
|
||||
queryset = music_models.Album.objects.with_tracks_count().order_by(
|
||||
"artist__name"
|
||||
)
|
||||
data = request.GET or request.POST
|
||||
filterset = filters.AlbumList2FilterSet(data, queryset=queryset)
|
||||
queryset = filterset.qs
|
||||
|
@ -223,7 +225,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
size = 50
|
||||
|
||||
size = min(size, 500)
|
||||
queryset = queryset[offset:size]
|
||||
queryset = queryset[offset : offset + size]
|
||||
data = {"albumList2": {"album": serializers.get_album_list2_data(queryset)}}
|
||||
return response.Response(data)
|
||||
|
||||
|
@ -283,7 +285,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
queryset = c["queryset"].filter(
|
||||
utils.get_query(query, c["search_fields"])
|
||||
)
|
||||
queryset = queryset[offset:size]
|
||||
queryset = queryset[offset : offset + size]
|
||||
payload["searchResult3"][c["subsonic"]] = c["serializer"](queryset)
|
||||
return response.Response(payload)
|
||||
|
||||
|
|
|
@ -217,6 +217,22 @@ def test_get_album_list2(f, db, logged_in_api_client, factories):
|
|||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("f", ["xml", "json"])
|
||||
def test_get_album_list2_pagination(f, db, logged_in_api_client, factories):
|
||||
url = reverse("api:subsonic-get-album-list2")
|
||||
assert url.endswith("getAlbumList2") is True
|
||||
album1 = factories["music.Album"]()
|
||||
factories["music.Album"]()
|
||||
response = logged_in_api_client.get(
|
||||
url, {"f": f, "type": "newest", "size": 1, "offset": 1}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.data == {
|
||||
"albumList2": {"album": serializers.get_album_list2_data([album1])}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("f", ["xml", "json"])
|
||||
def test_search3(f, db, logged_in_api_client, factories):
|
||||
url = reverse("api:subsonic-search3")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed broken pagination in Subsonic API (#295)
|
Loading…
Reference in New Issue