0001-api-add-more-filtering-possibility-to-users-API-fixe.patch
setup.py | ||
---|---|---|
122 | 122 |
'six>=1', |
123 | 123 |
'Markdown>=2.1', |
124 | 124 |
'python-ldap', |
125 |
'django-filter<0.12.0',
|
|
125 |
'django-filter', |
|
126 | 126 |
'pycrypto', |
127 | 127 |
'django-mellon', |
128 | 128 |
'ldaptools', |
src/authentic2/api_views.py | ||
---|---|---|
12 | 12 | |
13 | 13 |
from django_rbac.utils import get_ou_model, get_role_model |
14 | 14 | |
15 |
from rest_framework import serializers |
|
15 |
from rest_framework import serializers, pagination
|
|
16 | 16 |
from rest_framework.views import APIView |
17 | 17 |
from rest_framework.viewsets import ModelViewSet |
18 | 18 |
from rest_framework.routers import SimpleRouter |
... | ... | |
22 | 22 |
from rest_framework.exceptions import PermissionDenied |
23 | 23 |
from rest_framework.fields import CreateOnlyDefault |
24 | 24 | |
25 |
from django_filters.rest_framework import FilterSet |
|
26 | ||
25 | 27 |
from .custom_user.models import User |
26 | 28 |
from . import utils, decorators, attribute_kinds |
27 | 29 |
from .models import Attribute, PasswordReset |
... | ... | |
350 | 352 |
exclude = ('date_joined', 'user_permissions', 'groups', 'last_login') |
351 | 353 | |
352 | 354 | |
355 |
class UsersFilter(FilterSet): |
|
356 |
class Meta: |
|
357 |
model = get_user_model() |
|
358 |
fields = { |
|
359 |
'username': [ |
|
360 |
'exact', |
|
361 |
'iexact' |
|
362 |
], |
|
363 |
'first_name': [ |
|
364 |
'exact', |
|
365 |
'iexact', |
|
366 |
'icontains', |
|
367 |
'gte', |
|
368 |
'lte', |
|
369 |
'gt', |
|
370 |
'lt', |
|
371 |
], |
|
372 |
'last_name': [ |
|
373 |
'exact', |
|
374 |
'iexact', |
|
375 |
'icontains', |
|
376 |
'gte', |
|
377 |
'lte', |
|
378 |
'gt', |
|
379 |
'lt', |
|
380 |
], |
|
381 |
'modified': [ |
|
382 |
'gte', |
|
383 |
'lte', |
|
384 |
'gt', |
|
385 |
'lt', |
|
386 |
], |
|
387 |
'email': [ |
|
388 |
'exact', |
|
389 |
'iexact', |
|
390 |
], |
|
391 |
} |
|
392 | ||
393 | ||
353 | 394 |
class UsersAPI(ModelViewSet): |
354 |
filter_fields = ['username', 'first_name', 'last_name', 'email'] |
|
355 |
ordering_fields = ['username', 'first_name', 'last_name'] |
|
395 |
ordering_fields = ['username', 'first_name', 'last_name', 'modified', 'date_joined'] |
|
356 | 396 |
lookup_field = 'uuid' |
357 | 397 |
serializer_class = BaseUserSerializer |
398 |
filter_class = UsersFilter |
|
399 |
pagination_class = pagination.CursorPagination |
|
400 |
ordering = ['modified', 'id'] |
|
358 | 401 | |
359 | 402 |
def get_queryset(self): |
360 | 403 |
User = get_user_model() |
361 |
- |