Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
funkwhale
funkwhale
Commits
91f9b3af
Commit
91f9b3af
authored
Dec 21, 2021
by
Georg Krause
Browse files
Return the correct value for is_playable on albums
parent
142008cb
Pipeline
#17630
passed with stages
in 71 minutes and 2 seconds
Changes
3
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/music/serializers.py
View file @
91f9b3af
...
...
@@ -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
...
...
api/funkwhale_api/music/views.py
View file @
91f9b3af
...
...
@@ -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
))
...
...
api/tests/music/test_views.py
View file @
91f9b3af
...
...
@@ -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
}
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment