Created
December 7, 2010 00:02
-
-
Save jie/731233 to your computer and use it in GitHub Desktop.
A douban-group-like page style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if pageobj.shownav %} | |
<div class="articles-control"> | |
{% if pageobj.showprev %} | |
<span class="page-prev"><a href="/page/?start={{ pageobj.prevpage }}">PREV PAGE</a></span> | |
{% endif %} | |
<span class="page-number">{{pageobj.page}}</span> | |
{% if pageobj.shownext %} | |
<span class="page-next"><a href="/page/?start={{ pageobj.nextpage }}">NEXT PAGE</a></span> | |
{% endif %} | |
</div> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PageObj(object): | |
""" | |
A douban group like page style | |
""" | |
def __init__(self,pages,limit=10,start=10): | |
self.pages = pages | |
self.page = start/limit+1 | |
self.nextpage = self.page*limit | |
self.prevpage = (self.page-1)*limit-limit | |
if self.page*limit >= self.pages: | |
self.shownext = False | |
else: | |
self.shownext = True | |
if (self.page*limit)-limit <= 0: | |
self.showprev = False | |
else: | |
self.showprev = True | |
if self.pages <= limit: | |
self.shownav = False | |
else: | |
self.shownav = True | |
class MainPage(BlogBaseHandler): | |
def get(self, start=0): | |
allarticles = models.Article.all() | |
start = self.param("start") | |
if start.isdigit() is not True: | |
start = 0 | |
pageobj = PageObj(pages=allarticles.count(),limit=10,start=int(start)) | |
articles = models.Article.all().order('-created').fetch(limit=10,offset=int(start)) | |
self.render_to_response('template/index.html', { | |
'articles': articles, | |
'pageobj':pageobj, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment