示例#1
0
def archive_processor():
    if app.config["SITE_SIDEBAR_SHOW_ARCHIVE"]:
        mem = memcache.get('ARCHIVES')
        if mem is None:
            archives = []
            for archive in Archive.query().order(Archive.time).fetch():
                archives.append({
                    "post_count":
                    archive.post_count,
                    "year":
                    archive.time.strftime("%Y"),
                    "month":
                    archive.time.strftime("%m"),
                    "format_time":
                    archive.time.strftime(
                        app.config["SITE_SIDEBAR_ARCHIVE_DATE_FORMAT"])
                })
            memcache.add(key="ARCHIVES",
                         value=json.dumps(archives, encoding="utf-8"),
                         time=app.config["SITE_MEMCACHED_TIME"])
        else:
            archives = json.loads(mem, encoding="utf-8")
    else:
        archives = []
    return dict(archives=archives)
示例#2
0
文件: user.py 项目: qlqwl/Niflheim
def archive(year, month):
    a = Archive.query(Archive.time == date(year=int(year), month=int(month), day=1)).get()
    posts = Post.query(Post.archive == a.key, Post.status == Post.STATUS_PUBLISHED).order(-Post.modified).fetch()
    return render_template('archive.html', posts=posts, archive=a)