def show_archive_list(): site = Options.objects().first() pages = Content.objects(type="page", status=True) posts = Content.objects(type="post", status=True) created_time = [] for post in posts: created_time.append(post.created.strftime("%Y-%m-%d")) return render_template("archive_list.html", site=site, pages=pages, posts=posts, created_time=created_time)
def show_page(slug): site = Options.objects().first() pages = Content.objects(type="page", status=True) page = Content.objects(slug=slug).first() if page is not None: return render_template("page.html", site=site, pages=pages, page=page) else: # @todo: 添加自定义错误页面 return "404 not found"
def show_tag(slug, page=1): site = Options.objects().first() pages = Content.objects(type="page", status=True) title = '标签 "%s" 下的文章' % slug posts = Content.objects(tags=slug, status=True)[(page - 1) * 5: page * 5] pagination = Content.objects(tags=slug, status=True).paginate(page=page, per_page=5) created_time = [] for post in posts: created_time.append(post.created.strftime("%Y-%m-%d")) return render_template('archive.html', title=title, posts=posts, created_time=created_time, site=site, pages=pages, pagination=pagination, slug=slug)
def show_post(slug): site = Options.objects().first() pages = Content.objects(type="page", status=True) post = Content.objects(slug=slug).first() return render_template("post.html", site=site, pages=pages, post=post)
def index(page=1): site = Options.objects().first() posts = Content.objects(type="post", status=True)[(page - 1) * 5: page * 5] pages = Content.objects(type="page", status=True) pagination = Content.objects(type="post", status=True).paginate(page=page, per_page=5) return render_template("index.html", site=site, posts=posts, pages=pages, pagination=pagination)