Commit c48809bf authored by Agate's avatar Agate 💬

Merge branch '295-subsonic-pagination' into 'develop'

Resolve "Fix broken pagination in Subsonic getAlbumlist2"

Closes #295

See merge request funkwhale/funkwhale!244
parents 4c81de92 03178455
...@@ -208,7 +208,9 @@ class SubsonicViewSet(viewsets.GenericViewSet): ...@@ -208,7 +208,9 @@ class SubsonicViewSet(viewsets.GenericViewSet):
methods=["get", "post"], url_name="get_album_list2", url_path="getAlbumList2" methods=["get", "post"], url_name="get_album_list2", url_path="getAlbumList2"
) )
def get_album_list2(self, request, *args, **kwargs): 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 data = request.GET or request.POST
filterset = filters.AlbumList2FilterSet(data, queryset=queryset) filterset = filters.AlbumList2FilterSet(data, queryset=queryset)
queryset = filterset.qs queryset = filterset.qs
...@@ -223,7 +225,7 @@ class SubsonicViewSet(viewsets.GenericViewSet): ...@@ -223,7 +225,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
size = 50 size = 50
size = min(size, 500) size = min(size, 500)
queryset = queryset[offset:size] queryset = queryset[offset : offset + size]
data = {"albumList2": {"album": serializers.get_album_list2_data(queryset)}} data = {"albumList2": {"album": serializers.get_album_list2_data(queryset)}}
return response.Response(data) return response.Response(data)
...@@ -283,7 +285,7 @@ class SubsonicViewSet(viewsets.GenericViewSet): ...@@ -283,7 +285,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
queryset = c["queryset"].filter( queryset = c["queryset"].filter(
utils.get_query(query, c["search_fields"]) utils.get_query(query, c["search_fields"])
) )
queryset = queryset[offset:size] queryset = queryset[offset : offset + size]
payload["searchResult3"][c["subsonic"]] = c["serializer"](queryset) payload["searchResult3"][c["subsonic"]] = c["serializer"](queryset)
return response.Response(payload) return response.Response(payload)
......
...@@ -217,6 +217,22 @@ def test_get_album_list2(f, db, logged_in_api_client, factories): ...@@ -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"]) @pytest.mark.parametrize("f", ["xml", "json"])
def test_search3(f, db, logged_in_api_client, factories): def test_search3(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-search3") url = reverse("api:subsonic-search3")
......
Fixed broken pagination in Subsonic API (#295)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment