Skip to content

Commit

Permalink
feat: add id__in filter for scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed Jun 21, 2022
1 parent 4c3ab18 commit b7602a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion emeis/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django_filters.filters import CharFilter
from rest_framework import filters

from emeis.core.models import User
from emeis.core.models import Scope, User


class MonolingualSearchFilter(filters.SearchFilter):
Expand Down Expand Up @@ -67,3 +67,11 @@ def get_ordering(self, request, queryset, view):
if not ordering:
return ordering
return [self._make_ordering_field(field, view) for field in ordering]


class ScopeFilterset(FilterSet):
class Meta:
model = Scope
fields = {
"id": ["exact", "in"],
}
13 changes: 13 additions & 0 deletions emeis/core/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def test_declared_filters(
assert ret_users == []


def test_scope_id_filter(admin_client, scope_factory):
scope1, _, scope3 = scope_factory.create_batch(3)

resp = admin_client.get(
reverse("scope-list"),
{"filter[id__in]": ",".join([str(scope1.pk), str(scope3.pk)])},
)

ret_scopes = [us["id"] for us in resp.json()["data"]]

assert set(ret_scopes) == set([str(scope1.pk), str(scope3.pk)])


@pytest.mark.parametrize("sort", ["email", "-email"])
def test_user_ordering_case_insensitive(admin_client, admin_user, user_factory, sort):
emails = [
Expand Down
1 change: 1 addition & 0 deletions emeis/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class ScopeViewSet(BaseViewset):
"name",
"description",
]
filterset_class = filters.ScopeFilterset


class RoleViewSet(BaseViewset):
Expand Down

0 comments on commit b7602a9

Please sign in to comment.