views.py 995 B

123456789101112131415161718192021222324252627282930
  1. from django.contrib.auth.models import User, Group
  2. from rest_framework import viewsets
  3. from .serializers import UserSerializer, GroupSerializer
  4. from rest_framework.views import APIView
  5. from .permission import HasAPIKey, HAsKeyPermissionn
  6. from rest_framework.permissions import IsAuthenticated
  7. from .models import APIKey
  8. from rest_framework.decorators import api_view, permission_classes
  9. class UserViewSet(viewsets.ModelViewSet):
  10. """
  11. API endpoint that allows users to be viewed or edited.
  12. """
  13. queryset = User.objects.all().order_by('-date_joined')
  14. serializer_class = UserSerializer
  15. keys = APIKey.objects.all()
  16. for i in keys:
  17. print()
  18. permission_classes = [HasAPIKey | IsAuthenticated | HAsKeyPermissionn]
  19. class GroupViewSet(viewsets.ModelViewSet):
  20. """
  21. API endpoint that allows groups to be viewed or edited.
  22. """
  23. queryset = Group.objects.all()
  24. serializer_class = GroupSerializer
  25. permission_classes = [HasAPIKey | IsAuthenticated]