zoukankan      html  css  js  c++  java
  • 自定义的分页

    class Paginator(object):
        def __init__(self,totleCount,currentPage,perPageNum=4,maxPageNum=7):
            # 数据总个数
            self.totle_count = totleCount
            # 当前页
            try:
                v = int(currentPage)
                if v < 0:
                    v=1
                self.current_page = v
            except Exception as e:
                self.current_page = 1
            # 每页显示的行数
            self.per_page_item_num = perPageNum
            # 最大页码数
            self.max_page_num = maxPageNum
    
        def start(self):
            return (self.current_page-1)*self.per_page_item_num
    
        def end(self):
            return self.current_page * self.per_page_item_num
    
        @property
        def num_pages(self):
            # 总页数
            a,b = divmod(self.totle_count,self.per_page_item_num)
            if b == 0:
                return a
            return a+1
    
        def pager_num_range(self):
            # 当前页
            # self.current_pager
            # 最多显示页码的数量
            # self.per_pager_num
            # 总页数
            # self.num_pages
            # 如果 总页数 小于 最多显示页码数 返回  1--总页数
            if self.num_pages < self.max_page_num:
                return range(1, self.num_pages+1)
    
            part = self.max_page_num//2
            if self.current_page <= part:
                return range(1,self.max_page_num+1)
    
            if (self.current_page+part)>=self.num_pages:
                return range(self.num_pages-part,self.num_pages+1)
    
            return range(self.current_page-part,self.current_page+part+1)
    
        def page_str(self):
            page_list = []
            page_list.append('<ul class="pagination">')
            first = '<li><a href="/index?p=1" style="font-size:15px;">首页<a></li>'
            page_list.append(first)
    
            if self.current_page == 1:
                prev = '<li><a href="#" style="font-size:15px;">上一页<a></li>'
            else:
                prev = '<li><a href="/index?p=%s" style="font-size:15px;">上一页<a></li>'%(self.current_page-1)
            page_list.append(prev)
    
            for i in self.pager_num_range():
                if i == self.current_page:
                    temp = '<li class="active"><a href="/index?p=%s" style="font-size:30px;">%s</a></li>'%(i,i)
                else:
                    temp = '<li><a href="/index?p=%s" style="font-size:15px;">%s</a></li>' % (i, i)
                page_list.append(temp)
    
            if self.current_page == self.num_pages:
                prev = '<li><a href="#" style="font-size:15px;">下一页<a></li>'
            else:
                prev = '<li><a href="/index?p=%s" style="font-size:15px;">下一页<a></li>'%(self.current_page+1)
            page_list.append(prev)
    
            end = '<li><a href="/index?p=%s" style="font-size:15px;">尾页<a></li>'%(self.num_pages)
            page_list.append(end)
            page_list.append('</ul>')
            return ''.join(page_list)
    
        def stu_page_str(self):
            page_list = []
    
            first = '<li><a href="/students?p=1" style="font-size:15px;">首页<a></li>'
            page_list.append(first)
    
            if self.current_page == 1:
                prev = '<li><a href="#" style="font-size:15px;">上一页<a></li>'
            else:
                prev = '<li><a href="/students?p=%s" style="font-size:15px;">上一页<a></li>'%(self.current_page-1)
            page_list.append(prev)
    
            for i in self.pager_num_range():
                if i == self.current_page:
                    temp = '<li class="active"><a href="/students?p=%s" style="font-size:30px;">%s</a></li>'%(i,i)
                else:
                    temp = '<li><a href="/students?p=%s" style="font-size:15px;">%s</a></li>' % (i, i)
                page_list.append(temp)
    
            if self.current_page == self.num_pages:
                prev = '<li><a href="#" style="font-size:15px;">下一页<a></li>'
            else:
                prev = '<li><a href="/students?p=%s" style="font-size:15px;">下一页<a></li>'%(self.current_page+1)
            page_list.append(prev)
    
            end = '<li><a href="/students?p=%s" style="font-size:15px;">尾页<a></li>'%(self.num_pages)
            page_list.append(end)
    
            return ''.join(page_list)
    
        def tea_page_str(self):
            page_list = []
    
            first = '<li><a href="/teachers?p=1" style="font-size:15px;">首页<a></li>'
            page_list.append(first)
    
            if self.current_page == 1:
                prev = '<li><a href="#" style="font-size:15px;">上一页<a></li>'
            else:
                prev = '<li><a href="/teachers?p=%s" style="font-size:15px;">上一页<a></li>'%(self.current_page-1)
            page_list.append(prev)
    
            for i in self.pager_num_range():
                if i == self.current_page:
                    temp = '<li class="active"><a href="/teachers?p=%s" style="font-size:30px;">%s</a></li>'%(i,i)
                else:
                    temp = '<li><a href="/teachers?p=%s" style="font-size:15px;">%s</a></li>' % (i, i)
                page_list.append(temp)
    
            if self.current_page == self.num_pages:
                prev = '<li><a href="#" style="font-size:15px;">下一页<a></li>'
            else:
                prev = '<li><a href="/teachers?p=%s" style="font-size:15px;">下一页<a></li>'%(self.current_page+1)
            page_list.append(prev)
    
            end = '<li><a href="/teachers?p=%s" style="font-size:15px;">尾页<a></li>'%(self.num_pages)
            page_list.append(end)
    
            return ''.join(page_list)
  • 相关阅读:
    poi 导出Excel
    数据库连接太慢问题(3层for)
    mybatis 结果 返回的类中有集合的字段List<String>
    tomcat8 插件
    tomcat 7 到tomcat8 乱码问题
    简易代码生成器
    shiro权限控制用户登录的用法介绍
    导入maven工程并配置maven环境
    angularjs工程流程走不通的原因以及使用angularjs流程注意点
    访问路径:https://i.cnblogs.com/posts?categoryid=925678
  • 原文地址:https://www.cnblogs.com/Alone-Tree/p/9785801.html
Copyright © 2011-2022 走看看