當前位置: 首頁>>代碼示例>>Python>>正文


Python PageNumberPagination.get_paginated_response方法代碼示例

本文整理匯總了Python中rest_framework.pagination.PageNumberPagination.get_paginated_response方法的典型用法代碼示例。如果您正苦於以下問題:Python PageNumberPagination.get_paginated_response方法的具體用法?Python PageNumberPagination.get_paginated_response怎麽用?Python PageNumberPagination.get_paginated_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.pagination.PageNumberPagination的用法示例。


在下文中一共展示了PageNumberPagination.get_paginated_response方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_messages

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def get_messages(request, employee_id):
    """
    Get all messages for employee id
    ---
    response_serializer: activities.serializers.MessageSerializer
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden.
    - code: 404
      message: Not found
    - code: 500
      message: Internal Server Error
    """
    if request.method == 'GET':
        employee = get_object_or_404(Employee, pk=employee_id)
        messages = Message.objects.filter(
            Q(to_user='all') |
            Q(to_user=employee.location.name) |
            Q(to_user=employee.username))
        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(messages, request)
        serializer = MessageSerializer(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:belatrix,項目名稱:BackendAllStars,代碼行數:27,代碼來源:views.py

示例2: keyword_list

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def keyword_list(request):
    """
    Returns full keyword list ordered by name
    ---
    serializer: categories.serializers.KeywordSerializer
    parameters:
    - name: pagination
      required: false
      type: string
      paramType: query
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden.
    - code: 404
      message: Not found
    """
    if request.method == 'GET':
        keywords = get_list_or_404(Keyword, is_active=True)
        if request.GET.get('pagination'):
            pagination = request.GET.get('pagination')
            if pagination == 'true':
                paginator = PageNumberPagination()
                results = paginator.paginate_queryset(keywords, request)
                serializer = KeywordSerializer(results, many=True)
                return paginator.get_paginated_response(serializer.data)
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)
        else:
            serializer = KeywordSerializer(keywords, many=True)
            return Response(serializer.data, status=status.HTTP_200_OK)
開發者ID:belatrix,項目名稱:BackendAllStars,代碼行數:34,代碼來源:views.py

示例3: stars_keyword_list

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def stars_keyword_list(request):
    """
    Returns stars list grouped by keyword or result list if you use ?search=
    ---
    serializer: stars.serializers.StarKeywordList
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden, authentication credentials were not provided
    - code: 404
      message: Not found
    """
    if request.method == 'GET':
        if request.GET.get('search'):
            search_term = request.GET.get('search')
            star_list = Star.objects.filter(
                Q(keyword__name__icontains=search_term)).values('keyword__pk',
                                                                'keyword__name').annotate(num_stars=Count('keyword')).order_by('-num_stars')
        else:
            star_list = Star.objects.all().values('keyword__pk', 'keyword__name').annotate(num_stars=Count('keyword')).order_by('-num_stars')
        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(star_list, request)
        serializer = StarKeywordList(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:Gladislao,項目名稱:BackendAllStars,代碼行數:27,代碼來源:views.py

示例4: get_notifications

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def get_notifications(request, employee_id):
    """
    Get all notifications for employee id
    ---
    response_serializer: activities.serializers.NotificationSerializer
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden.
    - code: 404
      message: Not found
    - code: 500
      message: Internal Server Error
    """
    if request.method == 'GET':
        employee = get_object_or_404(Employee, pk=employee_id)
        activities = Activity.objects.annotate(
            profile=F('to_user')).values('datetime',
                                         'text',
                                         'profile').filter(to_user=employee)
        messages = Message.objects.annotate(
            profile=F('from_user')).values('datetime',
                                           'text',
                                           'profile').filter(Q(to_user='all') |
                                                             Q(to_user=employee.location.name) |
                                                             Q(to_user=employee.username))
        notifications = list(chain(activities, messages))
        notifications = sorted(notifications, reverse=True)
        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(notifications, request)
        serializer = NotificationSerializer(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:belatrix,項目名稱:BackendAllStars,代碼行數:35,代碼來源:views.py

示例5: stars_keyword_list_detail

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def stars_keyword_list_detail(request, keyword_id):
    """
    Returns stars list detail for keyword id.
    ---
    response_serializer: stars.serializers.StarTopEmployeeLists
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden, authentication credentials were not provided
    - code: 404
      message: Not found
    """
    if request.method == 'GET':
        keyword = get_object_or_404(Keyword, pk=keyword_id)
        stars = Star.objects.filter(keyword=keyword).values(
            'to_user__pk',
            'to_user__username',
            'to_user__first_name',
            'to_user__last_name',
            'to_user__level',
            'to_user__avatar').annotate(num_stars=Count('keyword')).order_by('-num_stars')
        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(stars, request)
        serializer = StarTopEmployeeLists(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:Gladislao,項目名稱:BackendAllStars,代碼行數:28,代碼來源:views.py

示例6: employee_list_group_by_badges_detail

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def employee_list_group_by_badges_detail(request, badge_id):
    """
    Returns employee list grouped by badge, you should provide badge_id
    ---
    response_serializer: stars.serializers.EmployeeGroupedListSerializer
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden, authentication credentials were not provided
    - code: 404
      message: Not found
    """
    if request.method == 'GET':
        badge = get_object_or_404(Badge, pk=badge_id)
        employee_list = EmployeeBadge.objects.filter(badge=badge).values(
            'to_user__pk',
            'to_user__username',
            'to_user__first_name',
            'to_user__last_name',
            'to_user__level',
            'to_user__avatar')
        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(employee_list, request)
        serializer = EmployeeGroupedListSerializer(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:belatrix,項目名稱:BackendAllStars,代碼行數:28,代碼來源:views.py

示例7: employee_list_group_by_badges

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def employee_list_group_by_badges(request):
    """
    Returns badge list with employee counter or result list if you use ?search=
    ---
    response_serializer: stars.serializers.EmployeeBadgeListSerializer
    parameters:
    - name: search
      required: false
      type: string
      paramType: query
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden, authentication credentials were not provided
    - code: 404
      message: Not found
    """
    if request.method == 'GET':
        if request.GET.get('search'):
            search_term = request.GET.get('search')
            badge_list = EmployeeBadge.objects.filter(
                Q(badge__name__icontains=search_term)).values(
                    'badge__pk',
                    'badge__name').annotate(num_employees=Count('to_user')).order_by('-num_employees')
        else:
            badge_list = EmployeeBadge.objects.all().values(
                'badge__pk',
                'badge__name').annotate(num_employees=Count('to_user')).order_by('-num_employees')
        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(badge_list, request)
        serializer = EmployeeBadgeListSerializer(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:belatrix,項目名稱:BackendAllStars,代碼行數:35,代碼來源:views.py

示例8: employee_skills_search

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def employee_skills_search(request, terms):
    """
    Returns the full employee list or result list from search skill terms
    ---
    serializer: employees.serializers.EmployeeListSerializer
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden.
    - code: 404
      message: Not found
    - code: 500
      message: Internal server error.
    """
    if request.method == 'GET':
        search_terms_array = terms.split()

        initial_term = search_terms_array[0]
        employee_list = Employee.objects.filter(skills__name__icontains=initial_term).annotate(Count('id'))

        if len(search_terms_array) > 1:
            for term in range(1, len(search_terms_array)):
                employee_list = employee_list.filter(search_terms_array[term])
    paginator = PageNumberPagination()
    results = paginator.paginate_queryset(employee_list, request)
    serializer = EmployeeListSerializer(results, many=True)
    return paginator.get_paginated_response(serializer.data)
開發者ID:Gladislao,項目名稱:BackendAllStars,代碼行數:30,代碼來源:views.py

示例9: employee_skill_remove

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def employee_skill_remove(request, employee_id):
    """
    Remove employee skill
    ---
    response_serializer: employees.serializers.EmployeeSkillsSerializer
    parameters:
    - name: skill
      type: string
      required: true
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden.
    - code: 404
      message: Not found
    - code: 500
      message: Internal Server Error
    """
    if request.method == 'PATCH':
        if 'skill' in request.data:
            skill = request.data['skill'].upper()
            keyword = get_object_or_404(Keyword, name=skill)
            employee = get_object_or_404(Employee, pk=employee_id)
            employee.skills.remove(keyword)
            employee.save()
            skills = employee.skills.all()
            paginator = PageNumberPagination()
            results = paginator.paginate_queryset(skills, request)
            serializer = EmployeeSkillsSerializer(results, many=True)
            return paginator.get_paginated_response(serializer.data)
開發者ID:Gladislao,項目名稱:BackendAllStars,代碼行數:33,代碼來源:views.py

示例10: other_location_events

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def other_location_events(request, employee_id):
    """
    Returns the full upcoming events list for employee location
    ---
    serializer: events.serializers.EventSerializer
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden.
    - code: 404
      message: Not found
    """
    events = []
    if request.method == 'GET':
        employee = get_object_or_404(Employee, pk=employee_id)
        events_list = Event.objects.filter(is_active=True)

        for event in events_list:
            if event.location != employee.location:
                events.append(event)

        paginator = PageNumberPagination()
        results = paginator.paginate_queryset(events, request)
        serializer = EventSerializer(results, many=True)
        return paginator.get_paginated_response(serializer.data)
開發者ID:belatrix,項目名稱:BackendAllStars,代碼行數:28,代碼來源:views.py

示例11: person

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
def person(request, pk=None, search=None, order=None):
    if request.method == 'GET' and pk==None:
        """
        Returns a JSON response with a listing of person objects
        """
        search = request.query_params.get('search')
        order = request.query_params.get('order') 

        if (search==None):
            search = '';

        if (order == None or order == ''):
            order = 'name'


        people = Person.objects.filter(name__istartswith=search).order_by(order).all()

        paginator = PageNumberPagination()    
        # From the docs:
        # The paginate_queryset method is passed the initial queryset 
        # and should return an iterable object that contains only the 
        # data in the requested page.
        result_page = paginator.paginate_queryset(people, request)
        # Now we just have to serialize the data
        serializer = PersonSerializer(result_page, many=True)
        # From the docs:
        # The get_paginated_response method is passed the serialized page 
        # data and should return a Response instance.
        return paginator.get_paginated_response(serializer.data)

    elif request.method == 'POST':
        serializer = PersonSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(photo = get_gravatar_url(serializer.data['email'], size=150))
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    try:
        person = Person.objects.get(pk=pk)
    except Person.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = PersonSerializer(person)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = PersonSerializer(person, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serilizer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        person.delete()
        serializer = PersonSerializer(person)
        return Response(serializer.data)
開發者ID:fernandodof,項目名稱:django-rest-tasks,代碼行數:61,代碼來源:views.py

示例12: list

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
 def list(self, request):
     self.check_permissions(request)
     paginator = PageNumberPagination()
     users = User.objects.all()
     paginator.paginate_queryset(users, request)
     serializer = UserSerializer(users, many=True)
     serializer_users = serializer.data
     return paginator.get_paginated_response(serializer_users)
開發者ID:snooze6,項目名稱:django-example,代碼行數:10,代碼來源:api.py

示例13: get_paginated_response

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
    def get_paginated_response(self):
        paginator = PageNumberPagination()

        page = paginator.paginate_queryset(self.queryset, self.request)

        model_serializer = self.serializer_class(page, many=True, context={"request": self.request})

        return paginator.get_paginated_response(model_serializer.data)
開發者ID:nickswebsite,項目名稱:gumshoe,代碼行數:10,代碼來源:views.py

示例14: get_page_response

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
 def get_page_response(self, query_set, request, serializer_class):
     """
     simple function to convert query set to rest framework paginated
     response,
     :param query_set: query set
     :param request: wsgi request
     :param serializer_class: serialzer for query set
     :return: paginated response.
     """
     paginator = PageNumberPagination()
     result_page = paginator.paginate_queryset(query_set, request)
     serializer = serializer_class(result_page, many=True)
     return paginator.get_paginated_response(serializer.data)
開發者ID:srkama,項目名稱:todo,代碼行數:15,代碼來源:api_rest.py

示例15: list

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import get_paginated_response [as 別名]
    def list(self, request):
        self.check_permissions(request)
        # Instanciar el paginador
        paginator = PageNumberPagination()
        users = User.objects.all()
        # Pagina el Queryset
        paginator.paginate_queryset(users, request)
        serializer = UserSerializer(users, many=True)
        serialized_users = serializer.data #Lista de diccionarios
        #renderer = JSONRenderer()
        #json_users = renderer.render(serialized_users) # Lista de diccionarios --> JSON

        # Devolver respuesta paginada
        return paginator.get_paginated_response(serialized_users)
開發者ID:lbarrous,項目名稱:Frikr,代碼行數:16,代碼來源:api.py


注:本文中的rest_framework.pagination.PageNumberPagination.get_paginated_response方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。