当前位置: 首页>>代码示例>>Python>>正文


Python ObjectPaginator.__init__方法代码示例

本文整理汇总了Python中django.core.paginator.ObjectPaginator.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectPaginator.__init__方法的具体用法?Python ObjectPaginator.__init__怎么用?Python ObjectPaginator.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.paginator.ObjectPaginator的用法示例。


在下文中一共展示了ObjectPaginator.__init__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import __init__ [as 别名]
    def __init__(self, request=None, query_set=None, current_page=1, page_size=20, padding=2):
        from re import sub

        ObjectPaginator.__init__(self, query_set, page_size)
        if request is None or query_set is None:
            raise Http404
        self.path = sub(r"p\d+/?$", "", request.path)
        self.path = sub(r"/$", "", self.path)
        self.query_str = "?" + request.GET.urlencode()
        if self.query_str == "?":
            self.query_str = ""
        try:
            self.current_page = int(current_page)
        except TypeError:
            self.current_page = 1
        self.page_size = page_size
        start = self.current_page - padding - 1
        end = self.current_page + padding - 1
        if start < 0:
            end += 0 - start
            start = 0
            if end >= self.pages:
                end = self.pages - 1
        if end >= self.pages:
            start -= end - self.pages + 1
            end = self.pages - 1
            if start < 0:
                start = 0
        self.first = start + 1
        self.last = end + 1
        self.base_url = self.path
        self.all_page_numbers = [
            {"page": p, "url": self.path + "/p" + str(p) + "/" + self.query_str} for p in range(1, self.pages + 1)
        ]
        self.page_numbers = [
            {"page": (p + 1), "url": self.path + "/p" + str(p + 1) + "/" + self.query_str}
            for p in range(start, end + 1)
        ]
        self.first_enabled = int(self.current_page) - padding > 1
        self.first_url = self.path + "/p1/" + self.query_str
        self.prev_enabled = int(self.current_page) > int(self.first)
        self.prev_url = self.path + "/p" + str(self.current_page - 1) + "/" + self.query_str
        self.next_enabled = int(self.current_page) < int(self.last)
        self.next_url = self.path + "/p" + str(self.current_page + 1) + "/" + self.query_str
        self.last_enabled = int(self.current_page) + padding < self.pages
        self.last_url = self.path + "/p" + str(self.pages) + "/" + self.query_str
        self.is_paginated = self.pages > 1
开发者ID:cstroie,项目名称:tranpy,代码行数:49,代码来源:paginator.py

示例2: __init__

# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import __init__ [as 别名]
 def __init__(self, query_set, page_size, link_template, total='?'):
     self.current_page = 1
     self.page_size = page_size
     self.link_template = link_template
     self.total = total
     ObjectPaginator.__init__(self, query_set, page_size)
开发者ID:yezooz,项目名称:24goals,代码行数:8,代码来源:better_paginator.py


注:本文中的django.core.paginator.ObjectPaginator.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。