Resolve "Pagination of results in genres in Subsonic API does not work"
This commit is contained in:
parent
ae0f7588e4
commit
69795b5ca2
|
@ -351,6 +351,12 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
queryset = queryset.playable_by(actor)
|
queryset = queryset.playable_by(actor)
|
||||||
|
try:
|
||||||
|
offset = int(data.get("offset", 0))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
|
||||||
|
offset = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
size = int(
|
size = int(
|
||||||
data["count"]
|
data["count"]
|
||||||
|
@ -369,7 +375,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
||||||
)
|
)
|
||||||
.prefetch_related("uploads")
|
.prefetch_related("uploads")
|
||||||
.distinct()
|
.distinct()
|
||||||
.order_by("-creation_date")[:size]
|
.order_by("-creation_date")[offset : offset + size]
|
||||||
)
|
)
|
||||||
data = {
|
data = {
|
||||||
"songsByGenre": {
|
"songsByGenre": {
|
||||||
|
|
|
@ -520,6 +520,23 @@ def test_get_songs_by_genre(f, tags_field, db, logged_in_api_client, factories):
|
||||||
assert response.data == expected
|
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"])
|
@pytest.mark.parametrize("f", ["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")
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed pagination in subsonic getSongsByGenre endpoint (#954)
|
Loading…
Reference in New Issue