Описание серилизаторов плюс карта
This commit is contained in:
1 parent
fd2644a2d6
commit
def0372449
10 files changed
+59
-286
No files matched your search
@@ -82,8 +82,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
def fio(self):
|
||||
|
||||
return self.user.login
|
||||
# return ShortUserSerializer(DictEmployee.objects.get(login=self.username)).data
|
||||
# return DictEmployee.objects.using('user_directory').get(login=self.username).fio
|
||||
|
||||
|
||||
def names(self):
|
||||
return DictEmployee.objects.get(login=self.username)
|
||||
|
||||
@@ -14,7 +14,6 @@ urlpatterns = [
|
||||
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
path('token/verify/', TokenVerifyView.as_view(), name='token_access'),
|
||||
path('getuser/', getuserAPIView.as_view(), name='getuserAPIView', ),
|
||||
path('test/', testView.as_view(), name='test')
|
||||
|
||||
|
||||
]
|
||||
@@ -1,86 +1,26 @@
|
||||
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(k.author.user),
|
||||
"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):
|
||||
"""
|
||||
Параметр: userlogin
|
||||
Пример: GET /api/accounts/getuser/?userlogin=9966-00-107
|
||||
Результат: Выдает все данные о пользователе
|
||||
"""
|
||||
dt=datetime.now()
|
||||
|
||||
queryset = DictEmployee.objects.get(login=request.query_params.get('userlogin'))
|
||||
r=CardUserSerializer(queryset).data
|
||||
|
||||
|
||||
|
||||
return Response(CardUserSerializer(queryset).data)
|
||||
|
||||
Reference in new issue
Block a user