Beispiel #1
0
def blog_comments():
    blog_id = request.values.get('blog_id', None)
    if not blog_id:
        return json.dumps(None).encode('utf-8')
    else:
        comments = Comment.find_all('blog_id=?', args=[blog_id])
        return json.dumps(dict(comments=comments), ensure_ascii=False, default=lambda o: o.__dict__).encode('utf-8')
Beispiel #2
0
def comments_update():
    '''
    保存评论
    :return:
    '''
    try:
        commentdata = json.loads(request.data.decode('utf-8'))
        comment = Comment(blog_id=commentdata['blog_id'], user_id=g.user.id,
                          user_name=g.user.name, user_image=g.user.image,
                          content=commentdata['content'], title=commentdata['title'])
        comment.content = markdown(comment.content, output_format='html')
        comment.save()
        comments = Comment.find_all('blog_id=?', args=[comment.blog_id])
        return json.dumps(dict(comments=comments), ensure_ascii=False, default=lambda o: o.__dict__).encode('utf-8')
    except BaseException as e:
        warning(e)
        return json.dumps(None).encode('utf-8')