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


Python urls.replace_query_param方法代碼示例

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


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

示例1: get_paginated_response

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_paginated_response(self, data):
        pagination_required = self.has_next or self.has_previous
        if not pagination_required:
            return Response(data)

        url = self.request.build_absolute_uri()
        pagination_map = {'first': replace_query_param(url, self.cursor_query_param, '')}

        if self.cursor_query_param not in self.request.query_params:
            count = self.queryset.count()
            data = {
                'detail': f'Pagination required. You can query up to {self.page_size} items at a time ({count} total). '
                          'Please use the `first` page link (see Link header).',
            }
            headers = self.construct_headers(pagination_map)
            return Response(data, headers=headers, status=status.HTTP_400_BAD_REQUEST)

        pagination_map.update(prev=self.get_previous_link(), next=self.get_next_link())
        headers = self.construct_headers(pagination_map)
        return Response(data, headers=headers) 
開發者ID:desec-io,項目名稱:desec-stack,代碼行數:22,代碼來源:pagination.py

示例2: get_previous_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_previous_link(request):
    """ Generate URL of previous page in pagination. """
    limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE))
    offset = int(request.query_params.get('offset', 0))

    if offset <= 0:
        return None

    url = request.build_absolute_uri()
    url = replace_query_param(url, 'limit', limit)

    if offset - limit <= 0:
        return remove_query_param(url, 'offset')

    offset = offset - limit
    return replace_query_param(url, 'offset', offset) 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:util.py

示例3: preserve_builtin_query_params

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def preserve_builtin_query_params(url, request=None):
    """
    Given an incoming request, and an outgoing URL representation,
    append the value of any built-in query parameters.
    """
    if request is None:
        return url

    overrides = [
        api_settings.URL_FORMAT_OVERRIDE,
    ]

    for param in overrides:
        if param and (param in request.GET):
            value = request.GET[param]
            url = replace_query_param(url, param, value)

    return url 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:20,代碼來源:reverse.py

示例4: get_html_context

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_html_context(self):
        base_url = self.request.build_absolute_uri()

        def page_number_to_url(page_number):
            if page_number == 1:
                return remove_query_param(base_url, self.page_query_param)
            else:
                return replace_query_param(base_url, self.page_query_param, page_number)

        current = self.page.number
        final = self.page.paginator.num_pages
        page_numbers = _get_displayed_page_numbers(current, final)
        page_links = _get_page_links(page_numbers, current, page_number_to_url)

        return {
            'previous_url': self.get_previous_link(),
            'next_url': self.get_next_link(),
            'page_links': page_links
        } 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:21,代碼來源:pagination.py

示例5: get_first_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_first_link(self):
        """Create first link with partial url rewrite."""
        url = self.request.build_absolute_uri()
        offset = 0
        first_link = replace_query_param(url, self.offset_query_param, offset)
        first_link = replace_query_param(first_link, self.limit_query_param, self.limit)
        return StandardResultsSetPagination.link_rewrite(self.request, first_link) 
開發者ID:project-koku,項目名稱:koku,代碼行數:9,代碼來源:pagination.py

示例6: get_last_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_last_link(self):
        """Create last link with partial url rewrite."""
        url = self.request.build_absolute_uri()
        offset = self.count - self.limit if (self.count - self.limit) >= 0 else 0
        last_link = replace_query_param(url, self.offset_query_param, offset)
        last_link = replace_query_param(last_link, self.limit_query_param, self.limit)
        return StandardResultsSetPagination.link_rewrite(self.request, last_link) 
開發者ID:project-koku,項目名稱:koku,代碼行數:9,代碼來源:pagination.py

示例7: build_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def build_link(self, index):
        if not index:
            return None
        url = self.request and self.request.build_absolute_uri() or ''
        return replace_query_param(url, self.page_query_param, index) 
開發者ID:django-json-api,項目名稱:django-rest-framework-json-api,代碼行數:7,代碼來源:pagination.py

示例8: get_last_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_last_link(self):
        if self.count == 0:
            return None

        url = self.request.build_absolute_uri()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        offset = (self.count // self.limit) * self.limit

        if offset <= 0:
            return remove_query_param(url, self.offset_query_param)

        return replace_query_param(url, self.offset_query_param, offset) 
開發者ID:django-json-api,項目名稱:django-rest-framework-json-api,代碼行數:15,代碼來源:pagination.py

示例9: get_next_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_next_link(request, count):
    """ Generate URL of next page in pagination. """
    limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE))
    offset = int(request.query_params.get('offset', 0))

    if offset + limit >= count:
        return None

    url = request.build_absolute_uri()
    url = replace_query_param(url, 'limit', limit)

    offset = offset + limit
    return replace_query_param(url, 'offset', offset) 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:15,代碼來源:util.py

示例10: get_next_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_next_link(self):
        if self.offset + self.limit >= self.count:
            return None

        url = self.request.get_full_path()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        offset = self.offset + self.limit
        return replace_query_param(url, self.offset_query_param, offset) 
開發者ID:ansible-community,項目名稱:ara,代碼行數:11,代碼來源:pagination.py

示例11: get_previous_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_previous_link(self):
        if self.offset <= 0:
            return None

        url = self.request.get_full_path()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        if self.offset - self.limit <= 0:
            return remove_query_param(url, self.offset_query_param)

        offset = self.offset - self.limit
        return replace_query_param(url, self.offset_query_param, offset) 
開發者ID:ansible-community,項目名稱:ara,代碼行數:14,代碼來源:pagination.py

示例12: get_last_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_last_link(self):
        if self.offset + self.limit >= self.count:
            return None
        url = self.request.get_full_path()
        url = replace_query_param(url, self.limit_query_param, self.limit)
        offset = self.count - self.limit
        return replace_query_param(url, self.offset_query_param, offset) 
開發者ID:ansible-community,項目名稱:ara,代碼行數:9,代碼來源:pagination.py

示例13: get_next_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_next_link(self):
        if self.offset + self.limit >= self.count:
            return None
        url = self.request.build_absolute_uri()
        offset = self.offset + self.limit
        return replace_query_param(
            url, self.start_query_param, self.queryset[offset].address
        ) 
開發者ID:openwisp,項目名稱:openwisp-ipam,代碼行數:10,代碼來源:views.py

示例14: get_previous_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_previous_link(self):
        if self.offset <= 0:
            return None
        url = self.request.build_absolute_uri()
        if self.offset - self.limit <= 0:
            return remove_query_param(url, self.start_query_param)
        offset = self.offset - self.limit
        return replace_query_param(
            url, self.start_query_param, self.queryset[offset].address
        ) 
開發者ID:openwisp,項目名稱:openwisp-ipam,代碼行數:12,代碼來源:views.py

示例15: get_last_link

# 需要導入模塊: from rest_framework.utils import urls [as 別名]
# 或者: from rest_framework.utils.urls import replace_query_param [as 別名]
def get_last_link(self):
        url = self.request.build_absolute_uri()
        page_number = self.page.paginator.num_pages
        return replace_query_param(url, self.page_query_param, page_number) 
開發者ID:silverapp,項目名稱:silver,代碼行數:6,代碼來源:pagination.py


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