예제 #1
0
    def GET(self):
        p = safe_number(web.input(page="1").page)
        limit = blog_settings.items_per_page
        offset = start_index(p, limit)
        pageCount = total_page(post_service.count_published(), limit)
        posts = post_service.get_published(offset, limit)
        nextLink = "?page=" + str(p + 1) if p < pageCount else None
        previousLink = "?page=" + str(p - 1) if p > 1 else None

        return render.index(posts, nextLink, previousLink)
 def GET(self, page=1):
     p = safe_number(page) 
     limit = blog_settings.items_per_page
     offset = start_index(p, limit)
     totalPosts = post_service.count_all()
     totalPostsPublished = post_service.count_published()
     pageCount = total_page(totalPostsPublished, limit) 
     posts = post_service.get_published(offset, limit)
     nextLink = str(p + 1) if p < pageCount else None
     previousLink = str(p - 1) if p > 1 else None 
     return render.posts(totalPosts, totalPostsPublished, posts, nextLink, previousLink)
 def fetch(self, key, max_age=5):            
     if self.cache.has_key(key):            
         if int(time.time()) - self.cache[key][0] < max_age:
             return self.cache[key][1]
     # Retrieve and cache        
     data = []
     if key == '_tags':
         data = tag_service.get_popular(5)
     elif key == '_pages':
         data = page_service.get_published(0, 5)
     elif key == '_posts':
         data = post_service.get_published(0, 10)           
     self.cache[key] = (time.time(), data)
     return data
예제 #4
0
    def GET(self, page):
        page = safe_number(page)
        if page < 1:
            return notfound("The requested resource was not found on this server.Pages start from 1")

        limit = blog_settings.items_per_page
        offset = start_index(page, limit)
        posts = post_service.get_published(offset, limit)
        page_count = total_page(len(posts), limit)
        nextLink = previousLink = None
        if page < page_count:
            nextLink = "/archives/" + str(page + 1)
        if page > 1:
            previousLink = "/archives/" + str(page - 1)

        return render.index(posts, nextLink, previousLink)