Commit ae781904 authored by Agate's avatar Agate 💬
Browse files

Merge branch '1145-random-ordering' into 'master'

Resolve "New API calls: random artist & track; others"

See merge request funkwhale/funkwhale!1150
parents 0ebd7c61 e6344338
......@@ -35,6 +35,7 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet):
fields=(
("creation_date", "creation_date"),
("artist__modification_date", "modification_date"),
("?", "random"),
)
)
......
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"]
......
......@@ -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"])
......
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