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)
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)
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)
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)
def tags(): tags = cache.get("tags") if tags is None: tags = Tag.query.cloud() cache.set("tags", tags) return dict(tags=tags)
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)
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)