Esempio n. 1
0
def delete_post(id):
    try:
        PostService.delete_post(id)
        flash(u'文章删除成功')
    except:
        flash(u'文章删除失败,请与管理员联系')

    return render_template('admin/show_posts.html')
Esempio 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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
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')
Esempio n. 7
0
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')
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
def post(id):
    post = PostService.get_one(id)
    cs = CommentService.get_comments(id)

    return render_template('admin/post.html', post=post, cs=cs)
Esempio n. 11
0
def show_posts():
    posts = PostService.get_posts()

    return render_template('admin/show_posts.html', posts=posts)
Esempio n. 12
0
def index():
    posts = PostService.get_posts()

    return render_template('web/index.html', posts=posts)
Esempio n. 13
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)
Esempio n. 14
0
def show_posts():
    posts = PostService.get_posts()

    return render_template('admin/show_posts.html', posts=posts)
Esempio n. 15
0
def index():
    posts = PostService.get_posts()

    return render_template('web/index.html', posts=posts)
Esempio n. 16
0
def post(id):
    post = PostService.get_one(id)
    cs = CommentService.get_comments(id)

    return render_template('admin/post.html', post=post, cs=cs)
Esempio n. 17
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)