from django.shortcuts import render

# Create your views here.
# Create your views here.
from django.contrib.auth.models import User
from rest_framework import generics
from rest_framework import mixins
from rest_framework import versioning
from rest_framework import viewsets

from .models import Party
from .serializers import PartySerializer
from .serializers import UserSerializer


class PartyList(mixins.ListModelMixin,
                mixins.CreateModelMixin,
                generics.GenericAPIView):
    queryset = Party.objects.all()
    serializer_class = PartySerializer

    def get(self, request, *args, **kwargs):
        return self.list(request, args, kwargs)

    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)


class PartyDetail(mixins.RetrieveModelMixin,
                  mixins.UpdateModelMixin,
                  mixins.DestroyModelMixin,
                  generics.GenericAPIView):
    queryset = Party.objects.all()
    serializer_class = PartySerializer

    def get(self, request, *args, **kwargs):
        return self.retrieve(request, *args, **kwargs)

    def put(self, request, *args, **kwargs):
        return self.update(request, *args, **kwargs)

    def delete(self, request, *args, **kwargs):
        return self.destroy(request, *args, **kwargs)


class PartyListSet(viewsets.ReadOnlyModelViewSet):
    queryset = Party.objects.all()
    serializer_class = PartySerializer


class UserList(generics.ListCreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    versioning_class = versioning.QueryParameterVersioning  # 版本

    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)
