def index(request, page=1): page = int(page) if page < 1: page = 1 page_size = 10 total = Post.count() post_list = Post.get_list(page, page_size) pager = Pager(total, page_size, page, page_list_num=8) return render_to_response("index.html", {"post_list": post_list, "pager": pager}, RequestContext(request))
def post_list(request): page = int(request.GET.get('page', 1)) if page < 1: page = 1 page_size = 15 total = Post.count() post_list = Post.get_list(page, page_size) pager = Pager(total, page_size, page, page_list_num = 10) return render_to_response('admin/post_list.html', { 'post_list': post_list, 'pager': pager, }, RequestContext(request))
def show_post(request, post_key): post = db.get(post_key) # 上一篇 和 下一篇 pre_post = Post.all().order("offset").filter("offset > ", post.offset).get() next_post = Post.all().order("-offset").filter("offset < ", post.offset).get() return render_to_response( "show_post.html", { "post": post, "pre_post": pre_post, "next_post": next_post, "user": get_user(), "comment_list": post.get_comment_list(), }, RequestContext(request), )
def sitemap(request): post_list = Post.get_list(1, 200) return render_to_response( "sitemap.xml", {"post_list": post_list, "blog_updated": datetime.datetime.utcnow()}, RequestContext(request), mimetype="text/xml; charset=utf-8", )
def atom(request): post_list = Post.get_list(1, 10) return render_to_response( "atom.xml", {"post_list": post_list, "blog_updated": datetime.datetime.utcnow()}, RequestContext(request), mimetype="application/atom+xml", )
def add_post_post(request): title = request.POST['title'].strip() content = request.POST['content'].strip() sep = '<hr class="more">' sep_index = content.find(sep) if sep_index != -1: summary = content[0:sep_index] else: summary = None add_time_date = request.POST.get('add_time_date').strip() add_time_time = request.POST.get('add_time_time').strip() if add_time_date and add_time_time: add_time = parse_time(add_time_date + ' '+ add_time_time) else: add_time = None Post.add(title, content, summary = summary, add_time = add_time) return HttpResponse('ok')