def delete_post(id): try: PostService.delete_post(id) flash(u'文章删除成功') except: flash(u'文章删除失败,请与管理员联系') return render_template('admin/show_posts.html')
def delete_post(post_id): post = PostService.get_one(post_id) if not post: return jsonify_with_error(APIError.NOT_FOUND) PostService.delete_post(post_id) return jsonify_with_data(APIError.OK)
def add_post(): title = request.form.get("title") content = request.form.get("content") post = PostService.add_post(title, content) return jsonify_with_data(APIError.OK, post=post)
def update_post(post_id): title = request.form.get("title") content = request.form.get("content") post = PostService.update_post(post_id, {"title": title, "content": content}) return jsonify_with_data(APIError.OK)
def get_posts(): offset = request.args.get("offset", 0, int) limit = request.args.get("limit", 10, int) posts = PostService.get_posts() return jsonify_with_data(APIError.OK, posts=posts)
def update_post(id): post = PostService.get_one(id) form = PostForm(title=post.get('title'), content=post.get('content')) if request.method == "GET": return render_template('admin/update_post.html', form=form) title = request.form['title'] content = request.form['content'] try: post = PostService.update_post(id, {'title': title, 'content': content}) flash(u'文章编辑成功') except: flash(u'文章编辑失败,请与管理员联系') return render_template('admin/show_posts.html')
def add_post(): form = PostForm(request.form) if request.method == "GET": return render_template('admin/add_post.html', form=form) title = form.title.data content = form.content.data try: post = PostService.add_post(title, content) flash(u'文章存入成功') except: flash(u'文章存入失败,请与管理员联系') return render_template('admin/index.html')
def post(id): form = CommentsForm(request.form) post = PostService.get_one(id) cs = CommentService.get_comments(id) if request.method == "GET": return render_template('web/post.html', form=form, post=post, cs=cs) post_id = int(id) name = form.name.data email = form.email.data comments = form.comments.data try: comment = CommentService.add_comment(post_id=post_id, name=name, email=email, comments=comments) flash('Add a comment successful!') except: flash('Failed to add a comment!') return render_template('web/post.html', form=form, post=post, cs=cs)
def post(id): form = CommentsForm(request.form) post = PostService.get_one(id) cs = CommentService.get_comments(id) if request.method == "GET": return render_template('web/post.html', form=form, post=post, cs=cs) post_id = int(id) name = form.name.data email = form.email.data comments = form.comments.data try: comment = CommentService.add_comment( post_id=post_id, name=name, email=email, comments=comments) flash('Add a comment successful!') except: flash('Failed to add a comment!') return render_template('web/post.html', form=form, post=post, cs=cs)
def post(id): post = PostService.get_one(id) cs = CommentService.get_comments(id) return render_template('admin/post.html', post=post, cs=cs)
def show_posts(): posts = PostService.get_posts() return render_template('admin/show_posts.html', posts=posts)
def index(): posts = PostService.get_posts() return render_template('web/index.html', posts=posts)
def get_post(post_id): post = PostService.get_one(post_id) if post is None: return jsonify_with_error(APIError.NOT_FOUNT) return jsonify_with_data(APIError.OK, post=post)