示例#1
0
 def get(self, request, format=None):
     paginator = api_settings.DEFAULT_PAGINATION_CLASS()
     return paginator.get_paginated_response(
         queryset=Loan.objects.all(),
         request=request,
         serializer=LoanDetailSerializer,
         serializer_kwargs={
             'fields': ('loan_id', 'amount', 'term',)
         }
     )
示例#2
0
    def get(self, request, *args, **kwargs):
        movie = Movie.objects.get(pk=kwargs.get("pk"))
        queryset = UserActivity.objects.filter(movie=movie)
        paginator = api_settings.DEFAULT_PAGINATION_CLASS()
        # OrderingFilter를 사용할 것 *공식 문서 참고
        paginator.ordering = "-pk"
        paged_comments = paginator.paginate_queryset(queryset, request)
        serial = UserCommentSerializer(paged_comments, many=True)

        return paginator.get_paginated_response(serial.data)
示例#3
0
def paginate_queryset(queryset: QuerySet, request: Request):
    queryset_paginated = queryset

    if request.query_params.get(REST_FRAMEWORK['PAGE_SIZE_QUERY_PARAM']) is not None:
        paginator = api_settings.DEFAULT_PAGINATION_CLASS()
        queryset_paginated = paginator.paginate_queryset(queryset, request)
        count_items = paginator.page.paginator.count
    else:
        count_items = queryset.count()

    return queryset_paginated, count_items
示例#4
0
文件: views.py 项目: luxu/codenation
 def get(self, request, format=None):
     paginator = api_settings.DEFAULT_PAGINATION_CLASS()
     return paginator.get_paginated_response(
         queryset=Client.objects.all(),
         request=request,
         serializer=ClientDetailSerializer,
         serializer_kwargs={'fields': (
             'client_id',
             'name',
             'cpf',
         )})
示例#5
0
    def get(self, request):
        queryset = Category.objects.all()

        if api_settings.DEFAULT_PAGINATION_CLASS:
            paginator = api_settings.DEFAULT_PAGINATION_CLASS()
            page = paginator.paginate_queryset(queryset, request, view=self)
            if page:
                serializer = CategorySerializer(page, many=True)
                return paginator.get_paginated_response(serializer.data)

        serializer = CategorySerializer(queryset, many=True)
        return Response(serializer.data)
示例#6
0
 def get_posts(self, obj):
     """
         Paginate user related posts, show latest first.
         Maybe there is better way to show related data paginated.
     """
     context = self.context
     request = context.get('request')
     if not request:
         return None
     paginator = api_settings.DEFAULT_PAGINATION_CLASS()
     page = paginator.paginate_queryset(obj.posts.order_by('-created'), request)
     serializer = UserDetailPostSerializer(page, many=True, context=context)
     return paginator.get_paginated_response(serializer.data).data
示例#7
0
def lostList(request):
    if request.method == 'POST':
        dictData = request.data.dict()
        dictData['user'] = request.user.id
        modifiedQueryDict = QueryDict('', mutable=True)
        modifiedQueryDict.update(dictData)
        serializer = LostSerializer(data=modifiedQueryDict)
        if serializer.is_valid():
            serializer.save()
            newLost = Lost.objects.get(id=serializer.data.get('id'))
            lostDate = newLost.created
            oneWeek = datetime.timedelta(days=7)
            relatedUsers = Found.objects.filter(
                itemType=serializer.data.get('itemType'),
                isComplete=False).values_list(
                    'user', 'created').order_by('user').distinct()
            for relatedUser in relatedUsers:
                if relatedUser[0] != request.user.id:
                    foundDate = relatedUser[1]
                    if lostDate - foundDate < oneWeek:
                        user = User.objects.get(id=relatedUser[0])
                        lostAlarm, created = LostAlarm.objects.get_or_create(
                            user=user, lost=newLost)
                        if created:
                            lostAlarm.save()
            return Response(
                data={'message': 'Lost list에 추가되었습니다'},
                status=status.HTTP_201_CREATED,
            )
        return Response(
            data={'message': '오류'},
            status=status.HTTP_403_FORBIDDEN,
        )
    elif request.method == 'GET':
        paginator = api_settings.DEFAULT_PAGINATION_CLASS()
        queryset = Lost.objects.all()
        page = paginator.paginate_queryset(queryset, request)
        serializers = LostRetrieveSerializer(page, many=True)
        return paginator.get_paginated_response(serializers.data)
示例#8
0
 def __init__(self, *args, **kwargs):
     self.paginator = api_settings.DEFAULT_PAGINATION_CLASS()
     super().__init__(*args, **kwargs)
示例#9
0
文件: views.py 项目: FiloSvR/GameHub
 def get_paginator(self):
     return api_settings.DEFAULT_PAGINATION_CLASS()