Commit bf5f5af7 by Douglas Hall Committed by Douglas Hall

Add ability to filter Program list by a comma-separated list of ProgramType names

WL-766
parent a3ae8b9f
...@@ -156,6 +156,7 @@ class CourseRunFilter(FilterSetMixin, django_filters.FilterSet): ...@@ -156,6 +156,7 @@ class CourseRunFilter(FilterSetMixin, django_filters.FilterSet):
class ProgramFilter(FilterSetMixin, django_filters.FilterSet): class ProgramFilter(FilterSetMixin, django_filters.FilterSet):
marketable = django_filters.MethodFilter() marketable = django_filters.MethodFilter()
type = django_filters.CharFilter(name='type__name', lookup_expr='iexact') type = django_filters.CharFilter(name='type__name', lookup_expr='iexact')
types = CharListFilter(name='type__slug', lookup_expr='in')
uuids = UUIDListFilter() uuids = UUIDListFilter()
class Meta: class Meta:
......
...@@ -127,6 +127,18 @@ class ProgramViewSetTests(SerializationMixin, APITestCase): ...@@ -127,6 +127,18 @@ class ProgramViewSetTests(SerializationMixin, APITestCase):
url = self.list_path + '?type=bar' url = self.list_path + '?type=bar'
self.assert_list_results(url, [], 4) self.assert_list_results(url, [], 4)
def test_filter_by_types(self):
""" Verify that the endpoint filters programs to those matching the provided ProgramType slugs. """
expected = ProgramFactory.create_batch(2)
expected.reverse()
type_slugs = [p.type.slug for p in expected]
url = self.list_path + '?types=' + ','.join(type_slugs)
# Create a third program, which should be filtered out.
ProgramFactory()
self.assert_list_results(url, expected, 8)
def test_filter_by_uuids(self): def test_filter_by_uuids(self):
""" Verify that the endpoint filters programs to those matching the provided UUIDs. """ """ Verify that the endpoint filters programs to those matching the provided UUIDs. """
expected = ProgramFactory.create_batch(2) expected = ProgramFactory.create_batch(2)
......
...@@ -77,6 +77,12 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -77,6 +77,12 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
type: integer type: integer
paramType: query paramType: query
multiple: false multiple: false
- name: types
description: Filter by comma-separated list of program type slugs
required: false
type: string
paramType: query
multiple: false
""" """
return super(ProgramViewSet, self).list(request, *args, **kwargs) return super(ProgramViewSet, self).list(request, *args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment