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


Python Paginator.get_page_numbers方法代碼示例

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


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

示例1: index

# 需要導入模塊: from the_tale.common.utils.pagination import Paginator [as 別名]
# 或者: from the_tale.common.utils.pagination.Paginator import get_page_numbers [as 別名]
    def index(self, page=None, place=None):

        records_query = Record.objects.all()

        if place is not None:
            records_query = records_query.filter(actors__place_id=place.id)

        url_builder = UrlBuilder(reverse('game:chronicle:'), arguments={'place': place.id if place else None})

        index_filter = IndexFilter(url_builder=url_builder, values={'place': place.id if place else None})

        records_count = records_query.count()

        if page is None:
            page = Paginator.get_page_numbers(records_count, chronicle_settings.RECORDS_ON_PAGE)
            if page == 0: page = 1
        page = int(page) - 1

        paginator = Paginator(page, records_count, chronicle_settings.RECORDS_ON_PAGE, url_builder, inverse=True)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        record_from, record_to = paginator.page_borders(page)

        records = [ RecordPrototype(record) for record in records_query.select_related().order_by('created_at', 'created_at_turn')[record_from:record_to]]

        records = list(reversed(records))

        return self.template('chronicle/index.html',
                             {'records': records,
                              'place': place,
                              'paginator': paginator,
                              'index_filter': index_filter,
                              'url_builder': url_builder} )
開發者ID:Alkalit,項目名稱:the-tale,代碼行數:37,代碼來源:views.py


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