Merge branch '954-pagination-subsonic-getsongsbygenre' into 'master'
Resolve "Pagination of results in genres in Subsonic API does not work" See merge request funkwhale/funkwhale!942
This commit is contained in:
commit
58780c47a1
|
@ -351,6 +351,12 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
)
|
||||
)
|
||||
queryset = queryset.playable_by(actor)
|
||||
try:
|
||||
offset = int(data.get("offset", 0))
|
||||
except (TypeError, ValueError):
|
||||
|
||||
offset = 0
|
||||
|
||||
try:
|
||||
size = int(
|
||||
data["count"]
|
||||
|
@ -369,7 +375,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
)
|
||||
.prefetch_related("uploads")
|
||||
.distinct()
|
||||
.order_by("-creation_date")[:size]
|
||||
.order_by("-creation_date")[offset : offset + size]
|
||||
)
|
||||
data = {
|
||||
"songsByGenre": {
|
||||
|
|
|
@ -520,6 +520,23 @@ def test_get_songs_by_genre(f, tags_field, db, logged_in_api_client, factories):
|
|||
assert response.data == expected
|
||||
|
||||
|
||||
def test_get_songs_by_genre_offset(logged_in_api_client, factories):
|
||||
url = reverse("api:subsonic-get_songs_by_genre")
|
||||
assert url.endswith("getSongsByGenre") is True
|
||||
track1 = factories["music.Track"](playable=True, set_tags=["Rock"])
|
||||
factories["music.Track"](playable=True, set_tags=["Rock"])
|
||||
factories["music.Track"](playable=True, set_tags=["Pop"])
|
||||
# the API order tracks by creation date DESC, so the second one
|
||||
# returned by the API is the first one to be created in the test.
|
||||
expected = {"songsByGenre": {"song": serializers.get_song_list_data([track1])}}
|
||||
|
||||
response = logged_in_api_client.get(
|
||||
url, {"f": "json", "count": 1, "offset": 1, "genre": "rock"}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("f", ["json"])
|
||||
def test_search3(f, db, logged_in_api_client, factories):
|
||||
url = reverse("api:subsonic-search3")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed pagination in subsonic getSongsByGenre endpoint (#954)
|
Loading…
Reference in New Issue