def __init__(self, page_size, page_number, query):
    self.page_size = page_size
    try:
        self.page_number = int(page_number)
    except ValueError:
        self.page_number = 1
    if (self.page_number < 1):
        self.page_number = 1
    self.query = query
    self.all_items = query.all()
    self.total_items = len(self.all_items)
    self.total_pages = (((self.total_items - 1) // page_size) + 1)
    if (self.page_number > self.total_pages):
        self.page_number = self.total_pages
    self.offset = (self.page_size * (self.page_number - 1))
    if (self.offset < 0):
        self.offset = 1
    self.items = self.all_items[self.offset:(self.offset + self.page_size)]
def __init__(self, page_size, page_number, query):
    self.page_size = page_size
    try:
        self.page_number = int(page_number)
    except ValueError:
        self.page_number = 1
    if (self.page_number < 1):
        self.page_number = 1
    self.query = query
    self.all_items = query.all()
    self.total_items = len(self.all_items)
    self.total_pages = (((self.total_items - 1) // page_size) + 1)
    if (self.page_number > self.total_pages):
        self.page_number = self.total_pages
    self.offset = (self.page_size * (self.page_number - 1))
    if (self.offset < 0):
        self.offset = 1
    self.items = self.all_items[self.offset:(self.offset + self.page_size)]