|
|
@@ -1,3 +1,26 @@ |
|
|
|
from django.shortcuts import render |
|
|
|
from rest_framework.response import Response |
|
|
|
from rest_framework.views import APIView |
|
|
|
from rest_framework.authentication import TokenAuthentication, SessionAuthentication |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
from .models import Representative, Role |
|
|
|
from .serializers import RoleSerializer, RepresentativeSerializer |
|
|
|
|
|
|
|
# Create your views here. |
|
|
|
|
|
|
|
class RoleList(APIView): |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
roles = Role.objects.all() |
|
|
|
serializer = RoleSerializer(roles, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class RepresentativeList(APIView): |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
representatives = Representative.objects.all() |
|
|
|
serializer = RepresentativeSerializer(representatives, many=True) |
|
|
|
return Response(serializer.data) |