CMSimple Drupal Yii 內容管理系統三方案 - 提升台灣中小企業競爭力

目前位置:   首頁 > CMS Projects > CherryPy 分頁列表

 CherryPy 分頁列表

def downloadlist_access_list(files, starti, endi):
    # files 為全部要列出的所有資料,  從 starti 列到 endi
    outstring = ""
    for 索引 in range(int(starti)-1, int(endi)):
        #filename_and_size = explode(":", $rowarray[$i]);
        outstring += "<a href=''>"+files[索引]+"</a><br />"
    return outstring
class 類別(object):
    # 略掉其他方法
    @cherrypy.expose
    def download_list(self, item_per_page=5, page=1, keyword=None):
        # cherrypy.session['admin'] = 1
        # cherrypy.session.get('admin')
        files = os.listdir(download_root_dir+"downloads/")
        total_rows = len(files)
        totalpage = math.ceil(total_rows/int(item_per_page))
        starti = int(item_per_page) * (int(page) - 1) + 1
        endi = starti + int(item_per_page) - 1
        outstring = ""
        notlast = False
        if total_rows > 0:
            # 準備在表格之前列印頁數資料
            # 開始最前頭的頁數資料列印
            outstring += "<br />"
            if (int(page) * int(item_per_page)) < total_rows:
                notlast = True
            if int(page) > 1:
                # 列出前往第一頁的連結
                outstring += "<a href='"
                outstring += "/download_list?&amp;page=1&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'><<</a> "
                page_num = int(page) - 1
                outstring += "<a href='"
                outstring += "/download_list?&amp;page="+str(page_num)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'>上一頁</a> "
            # 這裡希望能夠將總頁數以每 20 頁進行分段顯示,最多顯示出 span * 2 的頁數
            span = 10
            for 索引 in range(int(page)-span, int(page)+span):
            #for ($j=$page-$range;$j<$page+$range;$j++)
                if 索引>= 0 and 索引< totalpage:
                    page_now = 索引 + 1 
                    if page_now == int(page):
                        outstring += "<font size='+1' color='red'>"+str(page)+" </font>"
                    else:
                        outstring += "<a href='"
                        outstring += "/download_list?&amp;page="+str(page_now)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                        outstring += "'>"+str(page_now)+"</a> "
            if notlast == True:
                nextpage = int(page) + 1
                outstring += " <a href='"
                outstring += "/download_list?&amp;page="+str(nextpage)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'>下一頁</a>"
                #列出前往最後一頁的連結
                outstring += " <a href='"
                outstring += "/download_list?&amp;page="+str(totalpage)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'>>></a><br /><br />"
            # 完成最前頭的頁數資料
            # 列印最外圍的內容
            if (int(page) * int(item_per_page)) < total_rows:
                notlast = True
                outstring += downloadlist_access_list(files, starti, endi)+"<br />"
            else:
                outstring += "<br /><br />"
                outstring += downloadlist_access_list(files, starti, total_rows)+"<br />"
            
            if int(page) > 1:
                #列出前往第一頁的連結
                outstring += "<a href='"
                outstring += "/download_list?&amp;page=1&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'><<</a> "
                page_num = int(page) - 1
                outstring += "<a href='"
                outstring += "/download_list?&amp;page="+str(page_num)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'>上一頁</a> "
            # 這裡希望能夠將總頁數以每 20 頁進行分段顯示,最多顯示出 span * 2 的頁數
            span = 10
            for 索引 in range(int(page)-span, int(page)+span):
            #for ($j=$page-$range;$j<$page+$range;$j++)
                if 索引 >=0 and 索引 < totalpage:
                    page_now = 索引 + 1
                    if page_now == int(page):
                        outstring += "<font size='+1' color='red'>"+str(page)+" </font>"
                    else:
                        outstring += "<a href='"
                        outstring += "/download_list?&amp;page="+str(page_now)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                        outstring += "'>"+str(page_now)+"</a> "
            if notlast == True:
                nextpage = int(page) + 1
                outstring += " <a href='"
                outstring += "/download_list?&amp;page="+str(nextpage)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'>下一頁</a>"
                # 列出前往最後一頁的連結
                outstring += " <a href='"
                outstring += "/download_list?&amp;page="+str(totalpage)+"&amp;item_per_page="+str(item_per_page)+"&amp;keyword="+str(cherrypy.session.get('download_keyword'))
                outstring += "'>>></a>"
        else:
            outstring += "沒有資料!"
        return outstring+"<br/><br />"+self.mymenu()
    # 略掉其他方法

 

 

Powered by CMSimple_XH| Template: ge-webdesign.de| 登入