83 lines
3.0 KiB
Python
83 lines
3.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 navigation.models import *
|
|
from navigation.serializers import *
|
|
from userauth.serializers import *
|
|
from .models import *
|
|
from .serializers import *
|
|
import pandas as pd
|
|
|
|
|
|
class testView(APIView):
|
|
|
|
def get(self, request):
|
|
|
|
|
|
newsqueryset = News.objects.all().order_by('cdate')
|
|
|
|
|
|
|
|
for x in newsqueryset:
|
|
a=model_to_dict(x)
|
|
# a['link']= str(x.link.url)
|
|
# a['show'] = False
|
|
# a['showComment'] = False
|
|
# a['author'] = model_to_dict(DictEmployee.objects.using('user_directory').get(login=x.author.username))
|
|
a['scores'] = [{"score":y.score, "user":y.author.username} for y in x.get_news.all()]
|
|
a['comment'] = [{"author":model_to_dict(DictEmployee.objects.using('user_directory').get(login=k.author.username)),
|
|
"cdate":k.cdate,
|
|
"text":k.text,
|
|
"id": k.pk
|
|
} for k in x.get_comment_news.all()
|
|
]
|
|
|
|
return Response(NewsSerializer(newsqueryset, many=True).data)
|
|
# 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):
|
|
|
|
dt=datetime.now()
|
|
queryset = DictEmployee.objects.using('user_directory').get(login=request.query_params.get('userlogin'))
|
|
r=CardUserSerializer(queryset).data
|
|
print(datetime.now()-dt)
|
|
|
|
return Response(CardUserSerializer(queryset).data)
|
|
|