Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
jovuit
funkwhale
Commits
afc8f225
Commit
afc8f225
authored
Oct 21, 2019
by
Eliot Berriot
Browse files
Fix tag exclusion in custom radios (#950)
parent
afbf7151
Changes
3
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/radios/filters.py
View file @
afc8f225
...
...
@@ -30,7 +30,7 @@ def run(filters, **kwargs):
if
final_query
:
candidates
=
candidates
.
filter
(
final_query
)
return
candidates
.
order_by
(
"pk"
)
return
candidates
.
order_by
(
"pk"
)
.
distinct
()
def
validate
(
filter_config
):
...
...
@@ -100,7 +100,9 @@ class GroupFilter(RadioFilter):
conf
=
collections
.
ChainMap
(
filter_config
,
kwargs
)
query
=
f
.
get_query
(
candidates
,
**
conf
)
if
filter_config
.
get
(
"not"
,
False
):
query
=
~
query
# query = ~query *should* work but it doesn't (see #950)
# The line below generate a proper subquery
query
=
~
Q
(
pk__in
=
candidates
.
filter
(
query
).
values_list
(
"pk"
,
flat
=
True
))
if
not
final_query
:
final_query
=
query
...
...
api/tests/radios/test_radios.py
View file @
afc8f225
...
...
@@ -282,3 +282,41 @@ def test_session_radio_get_queryset_ignore_filtered_track_album_artist(
radio
.
start_session
(
user
=
cf
.
user
)
assert
radio
.
get_queryset
()
==
[
valid_track
]
def
test_get_choices_for_custom_radio_exclude_artist
(
factories
):
included_artist
=
factories
[
"music.Artist"
]()
excluded_artist
=
factories
[
"music.Artist"
]()
included_uploads
=
factories
[
"music.Upload"
].
create_batch
(
5
,
track__artist
=
included_artist
)
factories
[
"music.Upload"
].
create_batch
(
5
,
track__artist
=
excluded_artist
)
session
=
factories
[
"radios.CustomRadioSession"
](
custom_radio__config
=
[
{
"type"
:
"artist"
,
"ids"
:
[
included_artist
.
pk
]},
{
"type"
:
"artist"
,
"ids"
:
[
excluded_artist
.
pk
],
"not"
:
True
},
]
)
choices
=
session
.
radio
.
get_choices
(
filter_playable
=
False
)
expected
=
[
u
.
track
.
pk
for
u
in
included_uploads
]
assert
list
(
choices
.
values_list
(
"id"
,
flat
=
True
))
==
expected
def
test_get_choices_for_custom_radio_exclude_tag
(
factories
):
included_uploads
=
factories
[
"music.Upload"
].
create_batch
(
5
,
track__set_tags
=
[
"rap"
]
)
factories
[
"music.Upload"
].
create_batch
(
5
,
track__set_tags
=
[
"rock"
,
"rap"
])
session
=
factories
[
"radios.CustomRadioSession"
](
custom_radio__config
=
[
{
"type"
:
"tag"
,
"names"
:
[
"rap"
]},
{
"type"
:
"tag"
,
"names"
:
[
"rock"
],
"not"
:
True
},
]
)
choices
=
session
.
radio
.
get_choices
(
filter_playable
=
False
)
expected
=
[
u
.
track
.
pk
for
u
in
included_uploads
]
assert
list
(
choices
.
values_list
(
"id"
,
flat
=
True
))
==
expected
changes/changelog.d/950.bugfix
0 → 100644
View file @
afc8f225
Fix tag exclusion in custom radios (#950)
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