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 funkwhale_api.music import models
|
||||
from funkwhale_api.playlists import models as plt_models
|
||||
|
||||
|
||||
class RadioFilterRegistry(persisting_theory.Registry):
|
||||
|
@ -226,3 +227,20 @@ class TagFilter(RadioFilter):
|
|||
raise ValidationError("You must provide a name")
|
||||
except AssertionError:
|
||||
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):
|
||||
tracks = factories["music.Track"].create_batch(5)
|
||||
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():
|
||||
attr = value[:-1]
|
||||
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
|
||||
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop 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:
|
||||
return running.value
|
||||
? $pgettext('*/Player/Button.Label/Short, Verb', 'Stop radio')
|
||||
|
|
|
@ -30,7 +30,7 @@ export interface CurrentRadio {
|
|||
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()
|
||||
|
||||
|
|
|
@ -191,16 +191,17 @@ const labels = computed(() => ({
|
|||
const radioConfig = computed(() => {
|
||||
const results = Object.values(currentResults.value?.results ?? {})
|
||||
if (results.length) {
|
||||
if (currentType.value?.id === 'tags') {
|
||||
switch (currentType.value?.id) {
|
||||
case 'tags':
|
||||
return {
|
||||
type: 'tag',
|
||||
names: results.map(({ name }) => name)
|
||||
} as RadioConfig
|
||||
}
|
||||
|
||||
if (currentType.value?.id === 'artists') {
|
||||
case 'playlists':
|
||||
case 'artists':
|
||||
return {
|
||||
type: 'artist',
|
||||
type: currentType.value.id.slice(0, -1),
|
||||
ids: results.map(({ id }) => id)
|
||||
} as RadioConfig
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue