Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Philipp Wolfer
funkwhale
Commits
e6344338
Unverified
Commit
e6344338
authored
Jun 22, 2020
by
Agate
💬
Browse files
Fix
#1145
: Support ordering=random for artists, albums, tracks and channels endpoints
parent
0ebd7c61
Changes
3
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/audio/filters.py
View file @
e6344338
...
...
@@ -35,6 +35,7 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet):
fields
=
(
(
"creation_date"
,
"creation_date"
),
(
"artist__modification_date"
,
"modification_date"
),
(
"?"
,
"random"
),
)
)
...
...
api/funkwhale_api/music/filters.py
View file @
e6344338
from
django.db.models
import
Q
import
django_filters
from
django_filters
import
rest_framework
as
filters
from
funkwhale_api.audio
import
filters
as
audio_filters
...
...
@@ -80,6 +81,15 @@ class ArtistFilter(
scope
=
common_filters
.
ActorScopeFilter
(
actor_field
=
"tracks__uploads__library__actor"
,
distinct
=
True
)
ordering
=
django_filters
.
OrderingFilter
(
fields
=
(
(
"id"
,
"id"
),
(
"name"
,
"name"
),
(
"creation_date"
,
"creation_date"
),
(
"modification_date"
,
"modification_date"
),
(
"?"
,
"random"
),
)
)
class
Meta
:
model
=
models
.
Artist
...
...
@@ -118,6 +128,21 @@ class TrackFilter(
field_name
=
"_"
,
method
=
"filter_artist"
,
queryset
=
models
.
Artist
.
objects
.
all
()
)
ordering
=
django_filters
.
OrderingFilter
(
fields
=
(
(
"creation_date"
,
"creation_date"
),
(
"title"
,
"title"
),
(
"album__title"
,
"album__title"
),
(
"album__release_date"
,
"album__release_date"
),
(
"size"
,
"size"
),
(
"position"
,
"position"
),
(
"disc_number"
,
"disc_number"
),
(
"artist__name"
,
"artist__name"
),
(
"artist__modification_date"
,
"artist__modification_date"
),
(
"?"
,
"random"
),
)
)
class
Meta
:
model
=
models
.
Track
fields
=
{
...
...
@@ -207,6 +232,16 @@ class AlbumFilter(
actor_field
=
"tracks__uploads__library__actor"
,
distinct
=
True
)
ordering
=
django_filters
.
OrderingFilter
(
fields
=
(
(
"creation_date"
,
"creation_date"
),
(
"release_date"
,
"release_date"
),
(
"title"
,
"title"
),
(
"artist__modification_date"
,
"artist__modification_date"
),
(
"?"
,
"random"
),
)
)
class
Meta
:
model
=
models
.
Album
fields
=
[
"playable"
,
"q"
,
"artist"
,
"scope"
,
"mbid"
]
...
...
api/funkwhale_api/music/views.py
View file @
e6344338
...
...
@@ -130,7 +130,6 @@ class ArtistViewSet(
required_scope
=
"libraries"
anonymous_policy
=
"setting"
filterset_class
=
filters
.
ArtistFilter
ordering_fields
=
(
"id"
,
"name"
,
"creation_date"
,
"modification_date"
)
fetches
=
federation_decorators
.
fetches_route
()
mutations
=
common_decorators
.
mutations_route
(
types
=
[
"update"
])
...
...
@@ -187,12 +186,6 @@ class AlbumViewSet(
permission_classes
=
[
oauth_permissions
.
ScopePermission
]
required_scope
=
"libraries"
anonymous_policy
=
"setting"
ordering_fields
=
(
"creation_date"
,
"release_date"
,
"title"
,
"artist__modification_date"
,
)
filterset_class
=
filters
.
AlbumFilter
fetches
=
federation_decorators
.
fetches_route
()
...
...
@@ -345,17 +338,6 @@ class TrackViewSet(
required_scope
=
"libraries"
anonymous_policy
=
"setting"
filterset_class
=
filters
.
TrackFilter
ordering_fields
=
(
"creation_date"
,
"title"
,
"album__title"
,
"album__release_date"
,
"size"
,
"position"
,
"disc_number"
,
"artist__name"
,
"artist__modification_date"
,
)
fetches
=
federation_decorators
.
fetches_route
()
mutations
=
common_decorators
.
mutations_route
(
types
=
[
"update"
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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