Ticket #1795: 1795.diff

File 1795.diff, 2.4 KB (added by Marc Fargas <telenieko@…>, 8 years ago)

Uniffied diff (code, test, docs)

  • django/core/paginator.py

    === modified file 'django/core/paginator.py'
     
    2020        self.num_per_page = num_per_page
    2121        self.orphans = orphans
    2222        self._hits = self._pages = None
     23        self._page_range = None
    2324
    2425    def validate_page_number(self, page_number):
    2526        try:
     
    8384                hits = 0
    8485            self._pages = hits // self.num_per_page + 1
    8586        return self._pages
     87   
     88    def _get_page_range(self):
     89        """Returns a 1-based range of pages for iterating through within a template for loop."""
     90        if self._page_range is None:
     91            self._page_range = range(1, self._pages + 1)
     92        return self._page_range
    8693
    8794    hits = property(_get_hits)
    8895    pages = property(_get_pages)
     96    page_range = property(_get_page_range)
  • django/views/generic/list_detail.py

    === modified file 'django/views/generic/list_detail.py'
     
    6767            'first_on_page': paginator.first_on_page(page - 1),
    6868            'pages': paginator.pages,
    6969            'hits' : paginator.hits,
     70            'page_range' : paginator.page_range
    7071        }, context_processors)
    7172    else:
    7273        c = RequestContext(request, {
  • docs/generic_views.txt

    === modified file 'docs/generic_views.txt'
     
    762762    * ``hits``: The total number of objects across *all* pages, not just this
    763763      page.
    764764
     765    * ``page_range``: A list of the page numbers starting at 1, ideal for ``for``
     766      loops.
     767
    765768Notes on pagination
    766769~~~~~~~~~~~~~~~~~~~
    767770
     
    778781
    779782        /objects/?page=3
    780783
     784    * To loop over the possible page numbers use the ``page_range`` variable,
     785      for example, to place a link for every page.
     786
    781787In both cases, ``page`` is 1-based, not 0-based, so the first page would be
    782788represented as page ``1``.
    783789
  • tests/modeltests/pagination/models.py

    === modified file 'tests/modeltests/pagination/models.py'
     
    7777>>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1)
    7878>>> paginator.pages
    79792
     80>>> paginator.page_range
     81[1, 2]
    8082"""}
Back to Top