52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
from rest_framework import status
|
|
from rest_framework.permissions import AllowAny, IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
from .renderers import UserJSONRenderer
|
|
from userauth.models import *
|
|
from .models import *
|
|
# from .serializers import RegistrationSerializer
|
|
|
|
# class RegistrationAPIView(APIView):
|
|
# """
|
|
# Разрешить всем пользователям (аутентифицированным и нет) доступ к данному эндпоинту.
|
|
# """
|
|
# permission_classes = (AllowAny,)
|
|
# serializer_class = RegistrationSerializer
|
|
# renderer_classes = (UserJSONRenderer,)
|
|
|
|
# def post(self, request):
|
|
# user = request.data.get("user",{})
|
|
# # Паттерн создания сериализатора, валидации и сохранения - довольно
|
|
# # стандартный, и его можно часто увидеть в реальных проектах.
|
|
|
|
# serializer = self.serializer_class(data=user)
|
|
# serializer.is_valid(raise_exception=True)
|
|
# serializer.save()
|
|
|
|
# return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
|
|
class UserAPIView(APIView):
|
|
permission_classes = (IsAuthenticated,)
|
|
# serializer_class = RegistrationSerializer
|
|
def get(self, request):
|
|
# serializer = self.serializer_class(data=request.user)
|
|
# serializer.is_valid(raise_exception=True)
|
|
return Response('user')
|
|
|
|
class getuserAPIView(APIView):
|
|
permission_classes = (AllowAny,)
|
|
|
|
|
|
|
|
def get(self, request):
|
|
userlogin = request.query_params.get('userlogin')
|
|
print('--------------------------', self.request.query_params)
|
|
|
|
queryset = model_to_dict(DictEmployee.objects.using('user_directory').get(login=userlogin))
|
|
|
|
# queryset['responsible'] = [model_to_dict(x) for x in OrderResponsibilityEmployee.objects.using('user_directory').raw("SELECT * FROM order_responsibility_employee")]
|
|
|
|
return Response(queryset)
|
|
|