31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from django.shortcuts import render
|
|
from rest_framework.views import APIView
|
|
from .serializers import *
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.utils.decorators import method_decorator
|
|
from django.http import QueryDict
|
|
|
|
|
|
|
|
class FaceDetectionGetPostAPIView(APIView):
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
@method_decorator(csrf_exempt)
|
|
def dispatch(self, *args, **kwargs):
|
|
return super().dispatch(*args, **kwargs)
|
|
|
|
def post(self, request):
|
|
employee_id = request.user.employee_get.id
|
|
data = request.data
|
|
if isinstance(data, QueryDict):
|
|
data = data.dict()
|
|
data["employee_id"] = employee_id
|
|
serializer = EmployeeFaceDetectionSerializer(data=data)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|