Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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')
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def post(id):
    post = PostService.get_one(id)
    cs = CommentService.get_comments(id)

    return render_template('admin/post.html', post=post, cs=cs)
Ejemplo n.º 8
0
def post(id):
    post = PostService.get_one(id)
    cs = CommentService.get_comments(id)

    return render_template('admin/post.html', post=post, cs=cs)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)