本文整理汇总了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
示例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)