Beispiel #1
0
 def test_defaults(self):
     # Ensure the pages are returned correctly using the default values.
     pages = utils.get_page_numbers(10, 20)
     expected = [
         'previous', 1, 2, 3, None, 8, 9, 10, 11, 12,
         None, 18, 19, 20, 'next']
     self.assertSequenceEqual(expected, pages)
Beispiel #2
0
 def test_arrows(self):
     # Ensure the pages are returned correctly adding first / last arrows.
     pages = utils.get_page_numbers(5, 10, arrows=True)
     expected = [
         'first', 'previous', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'next', 'last'
     ]
     self.assertSequenceEqual(expected, pages)
Beispiel #3
0
 def test_defaults(self):
     # Ensure the pages are returned correctly using the default values.
     pages = utils.get_page_numbers(10, 20)
     expected = [
         'previous', 1, 2, 3, None, 8, 9, 10, 11, 12, None, 18, 19, 20,
         'next'
     ]
     self.assertSequenceEqual(expected, pages)
def show_pagination(context, pages):
    show = []
    for item in get_page_numbers(pages._page.number, len(pages)):
        if item is None:
            show.append(None)
        elif item == 'previous':
            show.append(pages.previous())
        elif item == 'next':
            show.append(pages.next())
        elif item == 'first':
            show.append(pages.first_as_arrow())
        elif item == 'last':
            show.append(pages.last_as_arrow())
        else:
            show.append(pages[item])

    return {'pages': show}
Beispiel #5
0
 def get_ajax_data(self, context, **kwargs):
     """
     Puts pagination data into response data.
     This method is intended to be overridden by the view to add actual payload.
     """       
     paginator = context['paginator']
     page = context['page_obj']
     pages = get_page_numbers(page.number, paginator.num_pages)
     data = {
         'pagination': {
            'num_pages': paginator.num_pages,
            'pages': pages,
            'count': paginator.count,
            'start_index': page.start_index(),
            'end_index': page.end_index()
         }
     }
     return data
Beispiel #6
0
 def test_last_page(self):
     # Ensure the correct pages are returned if the last page is requested.
     pages = utils.get_page_numbers(10, 10)
     expected = ['previous', 1, 2, 3, None, 8, 9, 10]
     self.assertSequenceEqual(expected, pages)
Beispiel #7
0
 def test_no_arounds(self):
     # Ensure the correct pages are returned with no arounds.
     pages = utils.get_page_numbers(10, 20, arounds=0)
     expected = ['previous', 1, 2, 3, None, 10, None, 18, 19, 20, 'next']
     self.assertSequenceEqual(expected, pages)
Beispiel #8
0
 def test_arrows_last_page(self):
     # Ensure the correct pages are returned if the last page is requested
     # adding first / last arrows.
     pages = utils.get_page_numbers(5, 5, arrows=True)
     expected = ['first', 'previous', 1, 2, 3, 4, 5]
     self.assertSequenceEqual(expected, pages)
Beispiel #9
0
 def test_first_page(self):
     # Ensure the correct pages are returned if the first page is requested.
     pages = utils.get_page_numbers(1, 10)
     expected = [1, 2, 3, None, 8, 9, 10, 'next']
     self.assertSequenceEqual(expected, pages)
 def test_fills_in_single_number_gaps(self):
     # It's pointless having a single (...) gap - best just fill it with
     # the missing number.
     pages = utils.get_page_numbers(6, 11, extremes=2, arounds=2)
     expected = ['previous', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 'next']
     self.assertSequenceEqual(expected, pages)
Beispiel #11
0
 def test_one_page(self):
     # Ensure the correct pages are returned if there is only one page.
     pages = utils.get_page_numbers(1, 1)
     expected = [1]
     self.assertSequenceEqual(expected, pages)
 def test_arrows_first_page(self):
     # Ensure the correct pages are returned if the first page is requested
     # adding first / last arrows.
     pages = utils.get_page_numbers(1, 5, arrows=True)
     expected = [1, 2, 3, 4, 5, 'next', 'last']
     self.assertSequenceEqual(expected, pages)
 def test_arrows_last_page(self):
     # Ensure the correct pages are returned if the last page is requested
     # adding first / last arrows.
     pages = utils.get_page_numbers(5, 5, arrows=True)
     expected = ['first', 'previous', 1, 2, 3, 4, 5]
     self.assertSequenceEqual(expected, pages)
Beispiel #14
0
 def test_no_extremes_arounds(self):
     # Ensure the correct pages are returned with no extremes and arounds.
     pages = utils.get_page_numbers(10, 20, extremes=0, arounds=0)
     expected = ['previous', 10, 'next']
     self.assertSequenceEqual(expected, pages)
Beispiel #15
0
 def test_arrows_first_page(self):
     # Ensure the correct pages are returned if the first page is requested
     # adding first / last arrows.
     pages = utils.get_page_numbers(1, 5, arrows=True)
     expected = [1, 2, 3, 4, 5, 'next', 'last']
     self.assertSequenceEqual(expected, pages)
Beispiel #16
0
 def test_one_page(self):
     # Ensure the correct pages are returned if there is only one page.
     pages = utils.get_page_numbers(1, 1)
     expected = [1]
     self.assertSequenceEqual(expected, pages)
Beispiel #17
0
 def test_no_extremes_arounds(self):
     # Ensure the correct pages are returned with no extremes and arounds.
     pages = utils.get_page_numbers(10, 20, extremes=0, arounds=0)
     expected = ['previous', 10, 'next']
     self.assertSequenceEqual(expected, pages)
Beispiel #18
0
 def test_no_arounds(self):
     # Ensure the correct pages are returned with no arounds.
     pages = utils.get_page_numbers(10, 20, arounds=0)
     expected = ['previous', 1, 2, 3, None, 10, None, 18, 19, 20, 'next']
     self.assertSequenceEqual(expected, pages)
Beispiel #19
0
 def test_last_page(self):
     # Ensure the correct pages are returned if the last page is requested.
     pages = utils.get_page_numbers(10, 10)
     expected = ['previous', 1, 2, 3, None, 8, 9, 10]
     self.assertSequenceEqual(expected, pages)
Beispiel #20
0
 def test_first_page(self):
     # Ensure the correct pages are returned if the first page is requested.
     pages = utils.get_page_numbers(1, 10)
     expected = [1, 2, 3, None, 8, 9, 10, 'next']
     self.assertSequenceEqual(expected, pages)
def page_list_callable_arrows(number, num_pages):
    """Wrap ``endless_pagination.utils.get_page_numbers``.

    Set first / last page arrows to True.
    """
    return utils.get_page_numbers(number, num_pages, arrows=True)
 def test_arrows(self):
     # Ensure the pages are returned correctly adding first / last arrows.
     pages = utils.get_page_numbers(5, 10, arrows=True)
     expected = [
         'first', 'previous', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'next', 'last']
     self.assertSequenceEqual(expected, pages)