当前位置: 首页>>代码示例>>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;未经允许,请勿转载。