python 分页插件
class MyPagePlugin(object): def __init__(self,totalItem,currentPage,url_a=None,perPageItem=3,showAPage=9): ''' :param totalItem: 总的条目数 :param perPageItem: 每页显示的条目 :param showAPage: 显示的页面链接,默认为9 :param currentPage: 显示的页面链接,默认为9 :param url_a: 组成页码的url ''' self.total_itme=totalItem self.per_page_item=perPageItem self.show_a_page=showAPage self.current_page=currentPage self.a_page_list=[] self.total_page=self.get_total_page self.url_a=url_a #列表的开始 @property def start(self): return (self.current_page-1)*self.per_page_item #列表的结束 @property def end(self): return self.current_page*self.per_page_item #总页数 @property def get_total_page(self): total_pages_num, b = divmod(self.total_itme, self.per_page_item) total_pages_num = total_pages_num + 1 if b else total_pages_num # 总页数 return total_pages_num #页码a链接列表 @property def getListPageA(self): ##############页码链接列表#################### # 首页 page_first = "<a href='%s?p=%s'>首页</a>" % (self.url_a,1) self.a_page_list.append(page_first) if self.current_page <= 5: for a_item in range(1, 9 + 1): if self.current_page == a_item: tem_a = "<a style='font-size:20px;color:red;' href='%s?p=%s'>%s</a>" % (self.url_a,a_item, a_item) else: tem_a = "<a href='%s?p=%s'>%s</a>" % (self.url_a,a_item, a_item) self.a_page_list.append(tem_a) elif self.current_page >= self.total_page - 4: for a_item in range(self.total_page - 9 + 1, self.total_page + 1): if self.current_page == a_item: tem_a = "<a style='font-size:20px;color:red;' href='%s?p=%s'>%s</a>" % (self.url_a,a_item, a_item) else: tem_a = "<a href='%s?p=%s'>%s</a>" % (self.url_a,a_item, a_item) self.a_page_list.append(tem_a) else: for a_item in range(self.current_page - 4, self.current_page + 4 + 1): if self.current_page == a_item: tem_a = "<a style='font-size:20px' href='%s?p=%s'>%s</a>" % (self.url_a,a_item, a_item) else: tem_a = "<a href='%s?p=%s'>%s</a>" % (self.url_a,a_item, a_item) self.a_page_list.append(tem_a) # 末页 page_last = "<a href='%s?p=%s'>末页</a>" % (self.url_a,self.total_page) self.a_page_list.append(page_last) return self.a_page_list