reorganized viewsets into their own files
This commit is contained in:
parent
83982877c3
commit
2e7dbe4ddc
13 changed files with 330 additions and 277 deletions
|
@ -1,40 +1,9 @@
|
|||
from django.contrib.auth import login
|
||||
from django.contrib.auth.models import Group, User, AnonymousUser
|
||||
from rest_framework import permissions, viewsets, status
|
||||
from knox.auth import TokenAuthentication
|
||||
from rest_framework import permissions
|
||||
from knox.views import LoginView as KnoxLoginView
|
||||
from rest_framework.authtoken.serializers import AuthTokenSerializer
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
from users.serializers import GroupSerializer, UserSerializer
|
||||
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
authentication_classes = [TokenAuthentication]
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
queryset = User.objects.all().order_by("-date_joined")
|
||||
serializer_class = UserSerializer
|
||||
|
||||
|
||||
class GroupViewSet(viewsets.ModelViewSet):
|
||||
authentication_classes = [TokenAuthentication]
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
queryset = Group.objects.all().order_by("name")
|
||||
serializer_class = GroupSerializer
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
def register(request):
|
||||
user_data = UserSerializer(data=request.data)
|
||||
|
||||
if user_data.is_valid():
|
||||
User.objects.create_user(**user_data.validated_data)
|
||||
return Response(request.data, status=status.HTTP_201_CREATED)
|
||||
else:
|
||||
return Response([], status=status.HTTP_400_BAD_REQUEST)
|
||||
from users.serializers import UserSerializer
|
||||
|
||||
|
||||
class LoginView(KnoxLoginView):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue