add playlists radio to search result page

environments/review-docs-pre-c-zs4ui8/deployments/15563
petitminion 2022-11-20 10:49:23 +00:00
rodzic 5fc613b21a
commit 01fd1503c9
6 zmienionych plików z 37 dodań i 13 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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]

Wyświetl plik

@ -0,0 +1 @@
Add playlists radio to search page (#1968)

Wyświetl plik

@ -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')

Wyświetl plik

@ -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()

Wyświetl plik

@ -191,18 +191,19 @@ const labels = computed(() => ({
const radioConfig = computed(() => {
const results = Object.values(currentResults.value?.results ?? {})
if (results.length) {
if (currentType.value?.id === 'tags') {
return {
type: 'tag',
names: results.map(({ name }) => name)
} as RadioConfig
}
switch (currentType.value?.id) {
case 'tags':
return {
type: 'tag',
names: results.map(({ name }) => name)
} as RadioConfig
if (currentType.value?.id === 'artists') {
return {
type: 'artist',
ids: results.map(({ id }) => id)
} as RadioConfig
case 'playlists':
case 'artists':
return {
type: currentType.value.id.slice(0, -1),
ids: results.map(({ id }) => id)
} as RadioConfig
}
// TODO (wvffle): Use logger