Commit 9b6c48aa authored by Eliot Berriot's avatar Eliot Berriot

Merge branch 'qa-017-round2' into 'develop'

Qa 017 round2

See merge request funkwhale/funkwhale!422
parents 6572db3a 58333b59
......@@ -147,13 +147,11 @@ class Playlist(models.Model):
class PlaylistTrackQuerySet(models.QuerySet):
def for_nested_serialization(self):
return (
self.select_related()
.select_related("track__album__artist")
.prefetch_related(
"track__tags", "track__uploads", "track__artist__albums__tracks__tags"
)
def for_nested_serialization(self, actor=None):
tracks = music_models.Track.objects.annotate_playable_by_actor(actor)
tracks = tracks.select_related("artist", "album__artist")
return self.prefetch_related(
models.Prefetch("track", queryset=tracks, to_attr="_prefetched_track")
)
def annotate_playable_by_actor(self, actor):
......
......@@ -10,18 +10,16 @@ from . import models
class PlaylistTrackSerializer(serializers.ModelSerializer):
track = TrackSerializer()
is_playable = serializers.SerializerMethodField()
# track = TrackSerializer()
track = serializers.SerializerMethodField()
class Meta:
model = models.PlaylistTrack
fields = ("id", "track", "playlist", "index", "creation_date", "is_playable")
fields = ("id", "track", "playlist", "index", "creation_date")
def get_is_playable(self, obj):
try:
return bool(obj.is_playable_by_actor)
except AttributeError:
return None
def get_track(self, o):
track = o._prefetched_track if hasattr(o, "_prefetched_track") else o.track
return TrackSerializer(track).data
class PlaylistTrackWriteSerializer(serializers.ModelSerializer):
......
......@@ -39,7 +39,9 @@ class PlaylistViewSet(
@detail_route(methods=["get"])
def tracks(self, request, *args, **kwargs):
playlist = self.get_object()
plts = playlist.playlist_tracks.all().for_nested_serialization()
plts = playlist.playlist_tracks.all().for_nested_serialization(
music_utils.get_actor_from_request(request)
)
serializer = serializers.PlaylistTrackSerializer(plts, many=True)
data = {"count": len(plts), "results": serializer.data}
return Response(data, status=200)
......@@ -59,7 +61,7 @@ class PlaylistViewSet(
plts = (
models.PlaylistTrack.objects.filter(pk__in=ids)
.order_by("index")
.for_nested_serialization()
.for_nested_serialization(music_utils.get_actor_from_request(request))
)
serializer = serializers.PlaylistTrackSerializer(plts, many=True)
data = {"count": len(plts), "results": serializer.data}
......@@ -97,7 +99,7 @@ class PlaylistTrackViewSet(
):
serializer_class = serializers.PlaylistTrackSerializer
queryset = models.PlaylistTrack.objects.all().for_nested_serialization()
queryset = models.PlaylistTrack.objects.all()
permission_classes = [
permissions.ConditionalAuthentication,
permissions.OwnerPermission,
......@@ -118,7 +120,7 @@ class PlaylistTrackViewSet(
lookup_field="playlist__privacy_level",
user_field="playlist__user",
)
).annotate_playable_by_actor(music_utils.get_actor_from_request(self.request))
).for_nested_serialization(music_utils.get_actor_from_request(self.request))
def perform_destroy(self, instance):
instance.delete(update_indexes=True)
......@@ -145,7 +145,7 @@ def test_can_list_tracks_from_playlist(level, factories, logged_in_api_client):
url = reverse("api:v1:playlists-tracks", kwargs={"pk": plt.playlist.pk})
response = logged_in_api_client.get(url)
serialized_plt = serializers.PlaylistTrackSerializer(plt).data
serialized_plt["track"]["is_playable"] = False
assert response.data["count"] == 1
assert response.data["results"][0] == serialized_plt
......
......@@ -306,7 +306,7 @@ html, body {
left: 350px;
right: 0px;
top: 0px;
z-index: 2000;
z-index: 99;
}
background-color: white;
.item {
......
......@@ -21,7 +21,7 @@
</div>
</h2>
<div class="ui hidden divider"></div>
<play-button class="orange" :tracks="tracks"><translate>Play all</translate></play-button>
<play-button class="orange" :is-playable="playlist.is_playable" :tracks="tracks"><translate>Play all</translate></play-button>
<button
class="ui icon button"
v-if="$store.state.auth.profile && playlist.user.id === $store.state.auth.profile.id"
......
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