From 9d1f839c9beb1042a2c5d54cd9385caf158a77ae Mon Sep 17 00:00:00 2001 From: Ryan Bannon Date: Thu, 9 Feb 2017 13:49:27 -0500 Subject: [PATCH] FEATURE: new GET query filter in user view ('in' filter) --- rodan/__init__.py | 4 ++-- rodan/views/user.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rodan/__init__.py b/rodan/__init__.py index 5ba110ed4..297e293d4 100644 --- a/rodan/__init__.py +++ b/rodan/__init__.py @@ -14,9 +14,9 @@ # Module version following PEP 396 # Get version: import rodan; rodan.__version__ -__version__ = "1.1.4" +__version__ = "1.1.5" -__copyright__ = "Copyright 2011-2016 Distributed Digital Music Archives & Libraries Lab" +__copyright__ = "Copyright 2011-2017 Distributed Digital Music Archives & Libraries Lab" # This will make sure the app is always imported when diff --git a/rodan/views/user.py b/rodan/views/user.py index 861306713..ab386adbc 100644 --- a/rodan/views/user.py +++ b/rodan/views/user.py @@ -12,6 +12,7 @@ from rodan.permissions import CustomObjectPermissions from rodan.serializers.user import UserSerializer, UserListSerializer +import django_filters class UserList(generics.ListCreateAPIView): """ @@ -27,6 +28,19 @@ class UserList(generics.ListCreateAPIView): _ignore_model_permissions = True serializer_class = UserListSerializer + class filter_class(django_filters.FilterSet): + username__in = django_filters.MethodFilter() + + def filter_username__in(self, q, v): + vs = v.split(',') + return q.filter(username__in=vs) + + class Meta: + model = User + fields = { + "username": ['in'] + } + def get_queryset(self): queryset = User.objects.exclude(pk=-1) return queryset