def post_new(): form = PostForm() if form.validate_on_submit(): title = form.title.data.encode('utf-8') content = form.content.data.encode('utf-8') author_id = g.user['id'] try: post = backend.add_post(title,author_id,content) except BackendError,ex: flash('新建内容失败请重试','error') return render_template('site/post_new.html',form=form) else: flash('新建列表成功','success') return redirect('/post/%d' % post['id'])
def post_edit(post_id): post = backend.get_post(post_id) if post['author_id'] != g.user_id: abort(403) form = PostForm(obj=post) if form.validate_on_submit(): title = form.title.data.encode('utf-8') content = form.content.data.encode('utf-8') try: post = backend.set_post(post_id,{ 'title':title, 'content':content }) except BackendError,ex: flash('内容修改失败,请检查重试','error') else: return redirect('/post/%d' % post_id)