54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework.permissions import IsAuthenticated # <-- Here
|
|
import json
|
|
from standards.models import Standards
|
|
from rest_framework import serializers
|
|
from .serializers import StandardsSerializer
|
|
from rest_framework.decorators import api_view, permission_classes
|
|
from rest_framework import status
|
|
from rest_framework.authentication import SessionAuthentication, BasicAuthentication, TokenAuthentication
|
|
from rest_framework.decorators import authentication_classes
|
|
|
|
class HelloView(APIView):
|
|
permission_classes = (IsAuthenticated,) # <-- And here
|
|
|
|
def post(self, request):
|
|
content = {'message': 'Hello, World!'}
|
|
return Response(content)
|
|
|
|
'''
|
|
class GiveMeStandards(APIView):
|
|
|
|
|
|
def post(self, request):
|
|
standards = Standards.objects.filter(agency=request.user.profile.agency)
|
|
|
|
content = {}
|
|
i = 0
|
|
for s in standards:
|
|
content.update({i : s.name.encode("utf-8")})
|
|
i += 1
|
|
|
|
content = {'standards': content}
|
|
return Response(content)
|
|
|
|
|
|
def post(self, request):
|
|
ser = StandardsSerializer(data=Standards.objects.filter(agency=self.request.user.profile.agency))
|
|
return Response(ser)
|
|
'''
|
|
|
|
@api_view(['POST', ])
|
|
@permission_classes((IsAuthenticated,))
|
|
def getStandardList(request):
|
|
standards = Standards.objects.filter(agency=request.user.profile.agency)
|
|
ser = StandardsSerializer(standards, many=True)
|
|
return Response(ser.data, status=status.HTTP_200_OK)
|
|
|
|
@api_view(['POST', ])
|
|
@permission_classes((IsAuthenticated,))
|
|
def getSingleStandard(request, pk):
|
|
standard = Standards.objects.get(pk=int(pk))
|
|
ser = StandardsSerializer(standard, many=False)
|
|
return Response(ser.data, status=status.HTTP_200_OK) |