Commit 91f9b3af authored by Georg Krause's avatar Georg Krause
Browse files

Return the correct value for is_playable on albums

parent 142008cb
......@@ -214,7 +214,10 @@ class AlbumSerializer(OptionalDescriptionMixin, serializers.Serializer):
def get_is_playable(self, obj):
try:
return any(
[bool(getattr(t, "playable_uploads", [])) for t in obj.tracks.all()]
[
bool(getattr(t, "is_playable_by_actor", None))
for t in obj.tracks.all()
]
)
except AttributeError:
return None
......
......@@ -185,9 +185,7 @@ class AlbumViewSet(
queryset = (
models.Album.objects.all()
.order_by("-creation_date")
.prefetch_related(
"artist__channel", "attributed_to", "attachment_cover", "tracks"
)
.prefetch_related("artist__channel", "attributed_to", "attachment_cover")
)
serializer_class = serializers.AlbumSerializer
permission_classes = [oauth_permissions.ScopePermission]
......@@ -223,8 +221,14 @@ class AlbumViewSet(
queryset = queryset.exclude(artist__channel=None).filter(
artist__attributed_to=self.request.user.actor
)
qs = queryset.prefetch_related(TAG_PREFETCH)
return qs
tracks = models.Track.objects.all().prefetch_related("album")
tracks = tracks.annotate_playable_by_actor(
utils.get_actor_from_request(self.request)
)
return queryset.prefetch_related(
Prefetch("tracks", queryset=tracks), TAG_PREFETCH
)
libraries = action(methods=["get"], detail=True)(
get_libraries(filter_uploads=lambda o, uploads: uploads.filter(track__album=o))
......
......@@ -58,7 +58,12 @@ def test_album_list_serializer(api_request, factories, logged_in_api_client):
).track
album = track.album
request = api_request.get("/")
qs = album.__class__.objects.with_tracks_count()
tracks = models.Track.objects.all().prefetch_related("album")
tracks = tracks.annotate_playable_by_actor(None)
qs = album.__class__.objects.with_tracks_count().annotate_playable_by_actor(None)
qs = qs.prefetch_related(Prefetch("tracks", queryset=tracks))
serializer = serializers.AlbumSerializer(
qs, many=True, context={"request": request}
)
......
Supports Markdown
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