You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
904 B

3 years ago
3 years ago
3 years ago
3 years ago
  1. from django.contrib.auth.models import User
  2. from django_filters.rest_framework import DjangoFilterBackend
  3. from rest_framework import filters, generics
  4. from rest_framework.permissions import IsAuthenticated
  5. from rest_framework.response import Response
  6. from rest_framework.views import APIView
  7. from ..permissions import IsProjectAdmin
  8. from ..serializers import UserSerializer
  9. class Me(APIView):
  10. permission_classes = (IsAuthenticated,)
  11. def get(self, request, *args, **kwargs):
  12. serializer = UserSerializer(request.user, context={'request': request})
  13. return Response(serializer.data)
  14. class Users(generics.ListAPIView):
  15. queryset = User.objects.all()
  16. serializer_class = UserSerializer
  17. permission_classes = [IsAuthenticated & IsProjectAdmin]
  18. pagination_class = None
  19. filter_backends = (DjangoFilterBackend, filters.SearchFilter)
  20. search_fields = ('username',)