|
|
@@ -1,56 +1,47 @@ |
|
|
|
from rest_framework.response import Response |
|
|
|
from rest_framework.views import APIView |
|
|
|
from rest_framework.authentication import TokenAuthentication, SessionAuthentication |
|
|
|
from .models import TaxType, Country, State, City, Client, Address |
|
|
|
from .serializers import TaxTypeSerializer, CountrySerializer, StateSerializer, CitySerializer, ClientSerializer, AddressSerializer |
|
|
|
from rest_framework import viewsets |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
from .models import TaxType, Country, State, City, Client |
|
|
|
from .serializers import TaxTypeSerializer, CountrySerializer, StateSerializer, CitySerializer, ClientSerializer |
|
|
|
from rest_framework.authentication import TokenAuthentication, SessionAuthentication |
|
|
|
|
|
|
|
|
|
|
|
class TaxTypeList(APIView): |
|
|
|
class TaxTypeViewSet(viewsets.ReadOnlyModelViewSet): |
|
|
|
queryset = TaxType.objects.all() |
|
|
|
serializer_class = TaxTypeSerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
tax_types = TaxType.objects.all() |
|
|
|
serializer = TaxTypeSerializer(tax_types, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class CountryList(APIView): |
|
|
|
class CountryViewSet(viewsets.ReadOnlyModelViewSet): |
|
|
|
queryset = Country.objects.all() |
|
|
|
serializer_class = CountrySerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
countries = Country.objects.all() |
|
|
|
serializer = CountrySerializer(countries, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class StateList(APIView): |
|
|
|
class StateViewSet(viewsets.ReadOnlyModelViewSet): |
|
|
|
queryset = State.objects.all() |
|
|
|
serializer_class = StateSerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
states = State.objects.all() |
|
|
|
serializer = StateSerializer(states, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class CityList(APIView): |
|
|
|
class CityViewSet(viewsets.ReadOnlyModelViewSet): |
|
|
|
queryset = City.objects.all() |
|
|
|
serializer_class = CitySerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
cities = City.objects.all() |
|
|
|
serializer = CitySerializer(cities, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class ClientList(APIView): |
|
|
|
class ClientViewSet(viewsets.ReadOnlyModelViewSet): |
|
|
|
queryset = Client.objects.all() |
|
|
|
serializer_class = ClientSerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
clients = Client.objects.all() |
|
|
|
serializer = ClientSerializer(clients, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
class AddressViewSet(viewsets.ReadOnlyModelViewSet): |
|
|
|
queryset = Address.objects.all() |
|
|
|
serializer_class = AddressSerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |