Пример #1
0
 def latest_comments():
     latest_comments = cache.get("latest_comments")
     if latest_comments is None:
         latest_comments = Comment.query.order_by(Comment.created_date.desc()) \
                                        .limit(5).all()
         cache.set("latest_comments", latest_comments)
     return dict(latest_comments=latest_comments)    
Пример #2
0
 def latest_comments():
     latest_comments = cache.get("latest_comments")
     if latest_comments is None:
         latest_comments = Comment.query.order_by(Comment.created_date.desc()) \
                                        .limit(5).all()
         cache.set("latest_comments", latest_comments)
     return dict(latest_comments=latest_comments)
Пример #3
0
    def archives():
        archives = cache.get("archives")
        if archives is None:
            begin_post = Post.query.filter(Post._page == False).order_by("created_date").first()

            now = datetime.datetime.now()

            begin = begin_post.created_date if begin_post else now
            end = now

            total = (end.year - begin.year) * 12 - begin.month + end.month
            archives = [begin]

            date = begin
            for i in range(total):
                if date.month < 12:
                    date = datetime.datetime(date.year, date.month + 1, 1)
                else:
                    date = datetime.datetime(date.year + 1, 1, 1)
                if Post.query.archive(date.year, date.month, None).count() > 0:
                    archives.append(date)
            archives.reverse()
            cache.set("archives", archives)

        return dict(archives=archives)
Пример #4
0
    def archives():
        archives = cache.get("archives")
        if archives is None:
            begin_post = Post.query.order_by('created_date').fitst()

            now = datetime.datetime.now()

            begin = begin_post.created_date if begin_post else now
            end = now

            total = (end.year-begin.year)*12 - begin.month + end.month
            archives = [begin]

            date = begin
            for i in range(total):
                if date.month<12:
                    date = datetime.datetime(date.year,date.month+1,1)
                else:
                    date = datetime.datetime(date.year+1,1,1)
                archives.reverse()
                cache.set("archives",archives)

        return dict(archives=archives)
Пример #5
0
    def archives():
        archives = cache.get("archives")
        if archives is None:
            begin_post = Post.query.order_by('created_date').first()

            now = datetime.datetime.now()

            begin = begin_post.created_date if begin_post else now
            end = now

            total = (end.year - begin.year) * 12 - begin.month + end.month
            archives = [begin]

            date = begin
            for i in range(total):
                if date.month < 12:
                    date = datetime.datetime(date.year, date.month + 1, 1)
                else:
                    date = datetime.datetime(date.year + 1, 1, 1)
                archives.append(date)
            archives.reverse()
            cache.set("archives", archives)

        return dict(archives=archives)
Пример #6
0
 def tags():
     tags = cache.get("tags")
     if tags is None:
         tags = Tag.query.cloud()
         cache.set("tags", tags)
     return dict(tags=tags)    
Пример #7
0
 def links():
     links = cache.get("links")
     if links is None:
         links = Link.query.filter(Link.passed==True).limit(10).all()
         cache.set("links", links)
     return dict(links=links)    
Пример #8
0
 def tags():
     tags = cache.get("tags")
     if tags is None:
         tags = Tag.query.cloud()
         cache.set("tags", tags)
     return dict(tags=tags)
Пример #9
0
 def links():
     links = cache.get("links")
     if links is None:
         links = Link.query.filter(Link.passed == True).limit(10).all()
         cache.set("links", links)
     return dict(links=links)