def category_1(cateid=1, pageid=1): categorys = Category.query.getall() hot = Post.query.hottest()[:20] new = Post.query.newpost()[:20] tag = Tag.query.getall() shuffle(tag) tag = tag[:20] comments = Comment.query.newcomment()[:20] cate = Category.query.get_or_404(cateid) p = pageby(cate.posts, pageid, per_page, Post.post_create_time.desc()) articles = p.items if not p.total: pagination = [0] elif p.total % per_page: pagination = range(1, p.total / per_page + 2) else: pagination = range(1, p.total / per_page + 1) return render_template('/category.html', id=cateid, cate=cate, categorys=categorys, articles=articles, hotarticles=hot, newpost=new, tags=tag, comments=comments, pageid=pageid, pagination=pagination[pageid - 1:pageid + 10], last_page=pagination[-1])
def tag_1(tagid=1, pageid=1): categorys = Category.query.getall() hot = Post.query.hottest()[:20] new = Post.query.newpost()[:20] tag = Tag.query.getall() shuffle(tag) tag = tag[:20] comments = Comment.query.newcomment()[:20] tagall = Tag.query.get_or_404(tagid) name = tagall.name p = Post.query.search_tag(name) p = pageby(p, pageid, per_page, Post.post_create_time.desc()) articles = p.items if not p.total: pagination = [0] elif p.total % per_page: pagination = range(1, p.total / per_page + 2) else: pagination = range(1, p.total / per_page + 1) return render_template('/tag.html', id=tagid, tagall=tagall, categorys=categorys, articles=articles, hotarticles=hot, newpost=new, tags=tag, comments=comments, pageid=pageid, pagination=pagination[pageid - 1:pageid + 10], last_page=pagination[-1] )
def search_1(pageid=1): categorys = Category.query.getall() hot = Post.query.hottest()[:20] new = Post.query.newpost()[:20] tag = Tag.query.getall() shuffle(tag) tag = tag[:20] comments = Comment.query.newcomment()[:20] searchword = request.args.get('s', '') if not searchword: return redirect(url_for('error_404')) searchresult = Post.query.search(searchword) p = pageby(searchresult, pageid, per_page, Post.post_create_time.desc()) articles = p.items if not p.total: pagination = [0] elif p.total % per_page: pagination = range(1, p.total / per_page + 2) else: pagination = range(1, p.total / per_page + 1) return render_template('/search.html', key=searchword, categorys=categorys, articles=articles, hotarticles=hot, newpost=new, tags=tag, comments=comments, pageid=pageid, pagination=pagination[pageid - 1:pageid + 10], last_page=pagination[-1] )
def search_1(pageid=1): categorys = Category.query.getall() hot = Post.query.hottest()[:20] new = Post.query.newpost()[:20] tag = Tag.query.getall() shuffle(tag) tag = tag[:20] comments = Comment.query.newcomment()[:20] searchword = request.args.get('s', '') if not searchword: return redirect(url_for('error_404')) searchresult = Post.query.search(searchword) p = pageby(searchresult, pageid, per_page, Post.post_create_time.desc()) articles = p.items if not p.total: pagination = [0] elif p.total % per_page: pagination = range(1, p.total / per_page + 2) else: pagination = range(1, p.total / per_page + 1) return render_template('/search.html', key=searchword, categorys=categorys, articles=articles, hotarticles=hot, newpost=new, tags=tag, comments=comments, pageid=pageid, pagination=pagination[pageid - 1:pageid + 10], last_page=pagination[-1])