Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andy Craze
funkwhale
Commits
7ae0b23c
Verified
Commit
7ae0b23c
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
See #170: filtering subscribed channels in API
parent
4236cc62
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/audio/filters.py
+21
-1
21 additions, 1 deletion
api/funkwhale_api/audio/filters.py
api/tests/audio/test_filters.py
+32
-0
32 additions, 0 deletions
api/tests/audio/test_filters.py
with
53 additions
and
1 deletion
api/funkwhale_api/audio/filters.py
+
21
−
1
View file @
7ae0b23c
from
django.db.models
import
Q
import
django_filters
from
funkwhale_api.common
import
fields
...
...
@@ -23,12 +25,30 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet):
)
tag
=
TAG_FILTER
scope
=
common_filters
.
ActorScopeFilter
(
actor_field
=
"
attributed_to
"
,
distinct
=
True
)
subscribed
=
django_filters
.
BooleanFilter
(
field_name
=
"
_
"
,
method
=
"
filter_subscribed
"
)
class
Meta
:
model
=
models
.
Channel
fields
=
[
"
q
"
,
"
scope
"
,
"
tag
"
]
fields
=
[
"
q
"
,
"
scope
"
,
"
tag
"
,
"
subscribed
"
]
hidden_content_fields_mapping
=
moderation_filters
.
USER_FILTER_CONFIG
[
"
CHANNEL
"
]
def
filter_subscribed
(
self
,
queryset
,
name
,
value
):
if
not
self
.
request
.
user
.
is_authenticated
:
return
queryset
.
none
()
emitted_follows
=
self
.
request
.
user
.
actor
.
emitted_follows
.
exclude
(
target__channel__isnull
=
True
)
query
=
Q
(
actor__in
=
emitted_follows
.
values_list
(
"
target
"
,
flat
=
True
))
if
value
is
True
:
return
queryset
.
filter
(
query
)
else
:
return
queryset
.
exclude
(
query
)
class
IncludeChannelsFilterSet
(
django_filters
.
FilterSet
):
"""
...
...
This diff is collapsed.
Click to expand it.
api/tests/audio/test_filters.py
0 → 100644
+
32
−
0
View file @
7ae0b23c
from
funkwhale_api.audio
import
filters
from
funkwhale_api.audio
import
models
def
test_channel_filter_subscribed_true
(
factories
,
mocker
,
queryset_equal_list
):
user
=
factories
[
"
users.User
"
](
with_actor
=
True
)
channel
=
factories
[
"
audio.Channel
"
]()
other_channel
=
factories
[
"
audio.Channel
"
]()
factories
[
"
audio.Subscription
"
](
target
=
channel
.
actor
,
actor
=
user
.
actor
)
factories
[
"
audio.Subscription
"
](
target
=
other_channel
.
actor
)
qs
=
models
.
Channel
.
objects
.
all
()
filterset
=
filters
.
ChannelFilter
(
{
"
subscribed
"
:
"
true
"
},
request
=
mocker
.
Mock
(
user
=
user
),
queryset
=
qs
)
assert
filterset
.
qs
==
[
channel
]
def
test_channel_filter_subscribed_false
(
factories
,
mocker
,
queryset_equal_list
):
user
=
factories
[
"
users.User
"
](
with_actor
=
True
)
channel
=
factories
[
"
audio.Channel
"
]()
other_channel
=
factories
[
"
audio.Channel
"
]()
factories
[
"
audio.Subscription
"
](
target
=
channel
.
actor
,
actor
=
user
.
actor
)
factories
[
"
audio.Subscription
"
](
target
=
other_channel
.
actor
)
qs
=
models
.
Channel
.
objects
.
all
()
filterset
=
filters
.
ChannelFilter
(
{
"
subscribed
"
:
"
false
"
},
request
=
mocker
.
Mock
(
user
=
user
),
queryset
=
qs
)
assert
filterset
.
qs
==
[
other_channel
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment