Example #1
0
 def get_pages_list(self):
     if not self._pages_list:
         callable_or_path = settings.PAGE_LIST_CALLABLE
         if callable_or_path:
             if callable(callable_or_path):
                 pages_callable = callable_or_path
             else:
                 pages_callable = loaders.load_object(callable_or_path)
         else:
             pages_callable = utils.get_page_numbers
         pages = []
         for item in pages_callable(self._page.number, len(self)):
             if item is None:
                 pages.append(None)
             elif item == 'previous':
                 pages.append(self.previous())
             elif item == 'next':
                 pages.append(self.next())
             elif item == 'first':
                 pages.append(self.first_as_arrow())
             elif item == 'last':
                 pages.append(self.last_as_arrow())
             else:
                 pages.append(self[item])
         self._pages_list = pages
     return self._pages_list
Example #2
0
 def get_pages_list(self):
     if not self._pages_list:
         callable_or_path = settings.PAGE_LIST_CALLABLE
         if callable_or_path:
             if callable(callable_or_path):
                 pages_callable = callable_or_path
             else:
                 pages_callable = loaders.load_object(callable_or_path)
         else:
             pages_callable = utils.get_page_numbers
         pages = []
         for item in pages_callable(self._page.number, len(self)):
             if item is None:
                 pages.append(None)
             elif item == 'previous':
                 pages.append(self.previous())
             elif item == 'next':
                 pages.append(self.next())
             elif item == 'first':
                 pages.append(self.first_as_arrow())
             elif item == 'last':
                 pages.append(self.last_as_arrow())
             else:
                 pages.append(self[item])
         self._pages_list = pages
     return self._pages_list
    def __unicode__(self):
        """Return a rendered Digg-style pagination (by default).

        The callable *settings.PAGE_LIST_CALLABLE* can be used to customize
        how the pages are displayed. The callable takes the current page number
        and the total number of pages, and must return a sequence of page
        numbers that will be displayed. The sequence can contain other values:

            - *'previous'*: will display the previous page in that position;
            - *'next'*: will display the next page in that position;
            - *'first'*: will display the first page as an arrow;
            - *'last'*: will display the last page as an arrow;
            - *None*: a separator will be displayed in that position.

        Here is an example of custom calable that displays the previous page,
        then the first page, then a separator, then the current page, and
        finally the last page::

            def get_page_numbers(current_page, num_pages):
                return ('previous', 1, None, current_page, 'last')

        If *settings.PAGE_LIST_CALLABLE* is None an internal callable is used,
        generating a Digg-style pagination. The value of
        *settings.PAGE_LIST_CALLABLE* can also be a dotted path to a callable.
        """
        if len(self) > 1:
            callable_or_path = settings.PAGE_LIST_CALLABLE
            if callable_or_path:
                if callable(callable_or_path):
                    pages_callable = callable_or_path
                else:
                    pages_callable = loaders.load_object(callable_or_path)
            else:
                pages_callable = utils.get_page_numbers
            pages = []
            for item in pages_callable(self._page.number, len(self)):
                if item is None:
                    pages.append(None)
                elif item == 'previous':
                    pages.append(self.previous())
                elif item == 'next':
                    pages.append(self.next())
                elif item == 'first':
                    pages.append(self.first_as_arrow())
                elif item == 'last':
                    pages.append(self.last_as_arrow())
                else:
                    pages.append(self[item])
            context = Context(self.context)
            context.update({'pages': pages})
            return loader.render_to_string('el_pagination/show_pages.html',
                                           context)
        return ''
Example #4
0
    def __unicode__(self):
        """Return a rendered Digg-style pagination (by default).

        The callable *settings.PAGE_LIST_CALLABLE* can be used to customize
        how the pages are displayed. The callable takes the current page number
        and the total number of pages, and must return a sequence of page
        numbers that will be displayed. The sequence can contain other values:

            - *'previous'*: will display the previous page in that position;
            - *'next'*: will display the next page in that position;
            - *'first'*: will display the first page as an arrow;
            - *'last'*: will display the last page as an arrow;
            - *None*: a separator will be displayed in that position.

        Here is an example of custom calable that displays the previous page,
        then the first page, then a separator, then the current page, and
        finally the last page::

            def get_page_numbers(current_page, num_pages):
                return ('previous', 1, None, current_page, 'last')

        If *settings.PAGE_LIST_CALLABLE* is None an internal callable is used,
        generating a Digg-style pagination. The value of
        *settings.PAGE_LIST_CALLABLE* can also be a dotted path to a callable.
        """
        if len(self) > 1:
            callable_or_path = settings.PAGE_LIST_CALLABLE
            if callable_or_path:
                if callable(callable_or_path):
                    pages_callable = callable_or_path
                else:
                    pages_callable = loaders.load_object(callable_or_path)
            else:
                pages_callable = utils.get_page_numbers
            pages = []
            for item in pages_callable(self._page.number, len(self)):
                if item is None:
                    pages.append(None)
                elif item == 'previous':
                    pages.append(self.previous())
                elif item == 'next':
                    pages.append(self.next())
                elif item == 'first':
                    pages.append(self.first_as_arrow())
                elif item == 'last':
                    pages.append(self.last_as_arrow())
                else:
                    pages.append(self[item])
            context = Context(self.context)
            context.update({'pages': pages})
            return loader.render_to_string('el_pagination/show_pages.html',
                                           context)
        return ''
Example #5
0
 def test_object_not_found(self):
     # An error is raised if the object cannot be found in the module.
     path = '.'.join((self.module, '__does_not_exist__'))
     with self.assertImproperlyConfigured('object'):
         loaders.load_object(path)
Example #6
0
 def test_invalid_module(self):
     # An error is raised if the provided path is not a valid dotted string.
     with self.assertImproperlyConfigured('invalid'):
         loaders.load_object('')
Example #7
0
 def test_module_not_found(self):
     # An error is raised if the module cannot be found.
     with self.assertImproperlyConfigured('not found'):
         loaders.load_object('__invalid__.module')
Example #8
0
 def test_valid_path(self):
     # Ensure the object is correctly loaded if the provided path is valid.
     path = '.'.join((self.module, 'test_object'))
     self.assertIs(test_object, loaders.load_object(path))
 def test_object_not_found(self):
     # An error is raised if the object cannot be found in the module.
     path = ".".join((self.module, "__does_not_exist__"))
     with self.assertImproperlyConfigured("object"):
         loaders.load_object(path)
 def test_invalid_module(self):
     # An error is raised if the provided path is not a valid dotted string.
     with self.assertImproperlyConfigured("invalid"):
         loaders.load_object("")
 def test_module_not_found(self):
     # An error is raised if the module cannot be found.
     with self.assertImproperlyConfigured("not found"):
         loaders.load_object("__invalid__.module")
 def test_valid_path(self):
     # Ensure the object is correctly loaded if the provided path is valid.
     path = ".".join((self.module, "test_object"))
     self.assertIs(test_object, loaders.load_object(path))