Beispiel #1
0
def post(id):

    #cForm = CommentForm(request.form)
    post = PostService.get_one(id)


    tags = [item.name for item in post['tags']]

    try:
        comments = CommentService.get_comments(int(id))
    except Exception:
        print(Exception)

    commentCount = len(comments)

    # get pre or next page
    try:
        next = PostService.get_next_post(id)
        if next is not None:
            nextId = next.id
        else:
            nextId = None
        pre = PostService.get_pre_post(id)
        if pre is not None:
            preId = pre.id
        else:
            preId = None
    except Exception as e:
        print(e)

    # get tag

    #if request.method == "GET":
    return render_template('web/post.html', post=post, cs = comments, count = commentCount, \
            nextPostId = nextId, prePostId = preId, tags = tags)
Beispiel #2
0
def comment():

    if request.method == 'POST':
        comment = request.json

        name = comment['name']
        email = comment['email']
        comContent = comment['comment']
        post_id = comment['post_id']

        post = PostService.get_one(post_id)

        if not post:
            return json.dumps({'has_error':True, "message":"文章不存在"})

        try:
            CommentService.add_comment(post_id=post_id, name=name, email=email, comments=comContent)
        except:
            return json.dumps({'has_error':True, "message":"存取出错"})

        return jsonify(success=True, message="评论成功", time=datetime.utcnow())