Example #1
0
    def __init__(self,
                 request,
                 number,
                 current_number,
                 total_number,
                 querystring_key,
                 label=None,
                 default_number=1,
                 override_path=None):
        self._request = request
        self.number = number
        self.current_number = current_number
        self.label = utils.text(number) if label is None else label
        self.querystring_key = querystring_key

        self.is_current = number == current_number
        self.is_first = number == 1
        self.is_last = number == total_number

        self.url = utils.get_querystring_for_page(
            request,
            number,
            self.querystring_key,
            default_number=default_number)
        path = iri_to_uri(override_path or request.path)
        self.path = '{0}{1}'.format(path, self.url)
 def check_page(
         self, page, number, is_first, is_last, is_current, label=None):
     """Perform several assertions on the given page attrs."""
     if label is None:
         label = utils.text(page.number)
     self.assertEqual(label, page.label)
     self.assertEqual(number, page.number)
     self.assertEqual(is_first, page.is_first)
     self.assertEqual(is_last, page.is_last)
     self.assertEqual(is_current, page.is_current)
 def test_page_list_render_using_arrows(self):
     # Ensure the page list is correctly rendered when using first / last
     # page arrows.
     page_list_callable = (
         'endless_pagination.tests.test_models.page_list_callable_arrows')
     with local_settings(PAGE_LIST_CALLABLE=page_list_callable):
         rendered = utils.text(self.pages)
     self.assertEqual(7, rendered.count('<a href'))
     self.assertIn(settings.FIRST_LABEL, rendered)
     self.assertIn(settings.LAST_LABEL, rendered)
 def render(self, context):
     # This template tag could raise a PaginationError: you have to call
     # *paginate* or *lazy_paginate* before including the getpages template.
     data = utils.get_data_from_context(context)
     # Return the string representation of the sequence of pages.
     pages = models.PageList(
         context['request'],
         data['page'],
         data['querystring_key'],
         default_number=data['default_number'],
         override_path=data['override_path'],
     )
     return utils.text(pages)
 def render(self, context):
     # This template tag could raise a PaginationError: you have to call
     # *paginate* or *lazy_paginate* before including the getpages template.
     data = utils.get_data_from_context(context)
     # Return the string representation of the sequence of pages.
     pages = models.PageList(
         context['request'],
         data['page'],
         data['querystring_key'],
         default_number=data['default_number'],
         override_path=data['override_path'],
     )
     return utils.text(pages)
    def __init__(
            self, request, number, current_number, total_number,
            querystring_key, label=None, default_number=1, override_path=None):
        self._request = request
        self.number = number
        self.label = utils.text(number) if label is None else label
        self.querystring_key = querystring_key

        self.is_current = number == current_number
        self.is_first = number == 1
        self.is_last = number == total_number

        self.url = utils.get_querystring_for_page(
            request, number, self.querystring_key,
            default_number=default_number)
        path = iri_to_uri(override_path or request.path)
        self.path = '{0}{1}'.format(path, self.url)
    def render(self, context):
        # Get the page number to use if it is not specified in querystring.
        if self.page_number_variable is None:
            default_number = self.page_number
        else:
            default_number = int(self.page_number_variable.resolve(context))

        # User can override the querystring key to use in the template.
        # The default value is defined in the settings file.
        if self.querystring_key_variable is None:
            querystring_key = self.querystring_key
        else:
            querystring_key = self.querystring_key_variable.resolve(context)

        # The request object is used to retrieve the current page number.
        page_number = utils.get_page_number_from_request(
            context['request'], querystring_key, default=default_number)

        if self.var_name is None:
            return utils.text(page_number)
        context[self.var_name] = page_number
        return ''
    def render(self, context):
        # Get the page number to use if it is not specified in querystring.
        if self.page_number_variable is None:
            default_number = self.page_number
        else:
            default_number = int(self.page_number_variable.resolve(context))

        # User can override the querystring key to use in the template.
        # The default value is defined in the settings file.
        if self.querystring_key_variable is None:
            querystring_key = self.querystring_key
        else:
            querystring_key = self.querystring_key_variable.resolve(context)

        # The request object is used to retrieve the current page number.
        page_number = utils.get_page_number_from_request(
            context['request'], querystring_key, default=default_number)

        if self.var_name is None:
            return utils.text(page_number)
        context[self.var_name] = page_number
        return ''
 def test_page_list_render_just_one_page(self):
     # Ensure nothing is rendered if the page list contains only one page.
     page = DefaultPaginator(range(10), 10).page(1)
     pages = models.PageList(self.request, page, self.page_label)
     self.assertEqual('', utils.text(pages))
 def test_page_list_render(self):
     # Ensure the page list is correctly rendered.
     rendered = utils.text(self.pages)
     self.assertEqual(5, rendered.count('<a href'))
     self.assertIn(settings.PREVIOUS_LABEL, rendered)
     self.assertIn(settings.NEXT_LABEL, rendered)
 def test_current_page_render(self):
     # Ensure the page is correctly rendered.
     page = self.pages.current()
     rendered_page = utils.text(page)
     self.assertNotIn('href', rendered_page)
     self.assertIn(page.label, rendered_page)
 def test_page_render(self):
     # Ensure the page is correctly rendered.
     page = self.pages.first()
     rendered_page = utils.text(page)
     self.assertIn('href="/"', rendered_page)
     self.assertIn(page.label, rendered_page)
 def check_page_list_callable(self, callable_or_path):
     """Check the provided *page_list_callable* is actually used."""
     with local_settings(PAGE_LIST_CALLABLE=callable_or_path):
         rendered = utils.text(self.pages).strip()
     expected = '<span class="endless_separator">...</span>'
     self.assertEqual(expected, rendered)