def test_get_post(self): user = backend.add_user('user02','*****@*****.**','pass02') post = Post(title='post01',author_id=user['id'],content='content01',pic_small='pic_small') db.session.add(post) db.session.commit() _post = backend.get_post(post.id) assert _post['title'] == 'post01'
def post_delete(post_id): post = backend.get_post(post_id) if post['author_id'] != g.user_id: abort(403) post = backend.set_post(post_id,{'show':False}) return redirect('/index')
def item_del(post_id, item_id): post = backend.get_post(post_id) item = backend.get_item(item_id) if g.user_id != post['author_id'] or item['post_id'] != post_id: abort(403) backend.set_item(item_id, {'show': False}) return redirect('/post/%d' % post_id)
def test_get_post(self): user = backend.add_user('user02', '*****@*****.**', 'pass02') post = Post(title='post01', author_id=user['id'], content='content01', pic_small='pic_small') db.session.add(post) db.session.commit() _post = backend.get_post(post.id) assert _post['title'] == 'post01'
def item_del(post_id, item_id): post = backend.get_post(post_id) item = backend.get_item(item_id) if g.user_id != post["author_id"] or item["post_id"] != post_id: abort(403) backend.set_item(item_id, {"show": False}) return redirect("/post/%d" % post_id)
def item_edit(post_id, item_id): post = backend.get_post(post_id) item = backend.get_item(item_id) if g.user_id != post["author_id"] or item["post_id"] != post_id: abort(403) form = ItemForm(**item) if form.validate_on_submit(): title = form.title.data.encode("utf-8") author_id = g.user_id atype = "" content = form.content.data try: item = backend.set_item(post_id, {"title": title, "content": content}) except BackendError, ex: flash("内容修改失败,请检查重试", "error")
def item_edit(post_id, item_id): post = backend.get_post(post_id) item = backend.get_item(item_id) if g.user_id != post['author_id'] or item['post_id'] != post_id: abort(403) form = ItemForm(**item) if form.validate_on_submit(): title = form.title.data.encode('utf-8') author_id = g.user_id atype = '' content = form.content.data try: item = backend.set_item(post_id, { 'title': title, 'content': content }) except BackendError, ex: flash('内容修改失败,请检查重试', 'error')
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)
def post_one(post_id): try: post = backend.get_post(post_id) except BackendError,ex: abort(404)