add playlists radio to search result page
This commit is contained in:
parent
5fc613b21a
commit
01fd1503c9
|
@ -6,6 +6,7 @@ from django.db.models import Q, functions
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from funkwhale_api.music import models
|
from funkwhale_api.music import models
|
||||||
|
from funkwhale_api.playlists import models as plt_models
|
||||||
|
|
||||||
|
|
||||||
class RadioFilterRegistry(persisting_theory.Registry):
|
class RadioFilterRegistry(persisting_theory.Registry):
|
||||||
|
@ -226,3 +227,20 @@ class TagFilter(RadioFilter):
|
||||||
raise ValidationError("You must provide a name")
|
raise ValidationError("You must provide a name")
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise ValidationError('No tag matching names "{}"'.format(diff))
|
raise ValidationError('No tag matching names "{}"'.format(diff))
|
||||||
|
|
||||||
|
|
||||||
|
@registry.register
|
||||||
|
class PlaylistFilter(RadioFilter):
|
||||||
|
code = "playlist"
|
||||||
|
label = "Playlist"
|
||||||
|
|
||||||
|
def get_query(self, candidates, ids, **kwargs):
|
||||||
|
playlists = plt_models.Playlist.objects.filter(id__in=ids)
|
||||||
|
ids_plts = []
|
||||||
|
for playlist in playlists:
|
||||||
|
ids = playlist.playlist_tracks.select_related("track").values_list(
|
||||||
|
"track_id", flat=True
|
||||||
|
)
|
||||||
|
for id in ids:
|
||||||
|
ids_plts.append(id)
|
||||||
|
return Q(id__in=ids_plts)
|
||||||
|
|
|
@ -418,7 +418,7 @@ def test_get_choices_for_custom_radio_exclude_tag(factories):
|
||||||
def test_can_start_custom_multiple_radio_from_api(api_client, factories):
|
def test_can_start_custom_multiple_radio_from_api(api_client, factories):
|
||||||
tracks = factories["music.Track"].create_batch(5)
|
tracks = factories["music.Track"].create_batch(5)
|
||||||
url = reverse("api:v1:radios:sessions-list")
|
url = reverse("api:v1:radios:sessions-list")
|
||||||
map_filters_to_type = {"tags": "names", "artists": "ids"}
|
map_filters_to_type = {"tags": "names", "artists": "ids", "playlists": "names"}
|
||||||
for (key, value) in map_filters_to_type.items():
|
for (key, value) in map_filters_to_type.items():
|
||||||
attr = value[:-1]
|
attr = value[:-1]
|
||||||
track_filter_key = [getattr(a.artist, attr) for a in tracks]
|
track_filter_key = [getattr(a.artist, attr) for a in tracks]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add playlists radio to search page (#1968)
|
|
@ -47,6 +47,10 @@ const buttonLabel = computed(() => {
|
||||||
return running.value
|
return running.value
|
||||||
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop artists radio')
|
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop artists radio')
|
||||||
: $pgettext('*/Player/Button.Label/Short, Verb', 'Start artists radio')
|
: $pgettext('*/Player/Button.Label/Short, Verb', 'Start artists radio')
|
||||||
|
case 'playlist':
|
||||||
|
return running.value
|
||||||
|
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop playlists radio')
|
||||||
|
: $pgettext('*/Player/Button.Label/Short, Verb', 'Start playlists radio')
|
||||||
default:
|
default:
|
||||||
return running.value
|
return running.value
|
||||||
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop radio')
|
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop radio')
|
||||||
|
|
|
@ -30,7 +30,7 @@ export interface CurrentRadio {
|
||||||
objectId: ObjectId | null
|
objectId: ObjectId | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RadioConfig = { type: 'tag', names: string[] } | { type: 'artist', ids: string[] }
|
export type RadioConfig = { type: 'tag', names: string[] } | { type: 'artist' | 'playlist', ids: string[] }
|
||||||
|
|
||||||
const logger = useLogger()
|
const logger = useLogger()
|
||||||
|
|
||||||
|
|
|
@ -191,18 +191,19 @@ const labels = computed(() => ({
|
||||||
const radioConfig = computed(() => {
|
const radioConfig = computed(() => {
|
||||||
const results = Object.values(currentResults.value?.results ?? {})
|
const results = Object.values(currentResults.value?.results ?? {})
|
||||||
if (results.length) {
|
if (results.length) {
|
||||||
if (currentType.value?.id === 'tags') {
|
switch (currentType.value?.id) {
|
||||||
return {
|
case 'tags':
|
||||||
type: 'tag',
|
return {
|
||||||
names: results.map(({ name }) => name)
|
type: 'tag',
|
||||||
} as RadioConfig
|
names: results.map(({ name }) => name)
|
||||||
}
|
} as RadioConfig
|
||||||
|
|
||||||
if (currentType.value?.id === 'artists') {
|
case 'playlists':
|
||||||
return {
|
case 'artists':
|
||||||
type: 'artist',
|
return {
|
||||||
ids: results.map(({ id }) => id)
|
type: currentType.value.id.slice(0, -1),
|
||||||
} as RadioConfig
|
ids: results.map(({ id }) => id)
|
||||||
|
} as RadioConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (wvffle): Use logger
|
// TODO (wvffle): Use logger
|
||||||
|
|
Loading…
Reference in New Issue