Exemple #1
0
def reply():
    articleid = request.form.get('articleid')
    commentid = request.form.get('commentid')
    content = request.form.get('content').strip()
    ipaddr = request.remote_addr

    # 如果评论的字数低于5个或多于1000,视为不合法
    if len(content) < 5 or len(content) > 1000:
        return 'content-invalid'

    comment = Comment()
    # 没有超出限制才能发表评论
    if not comment.check_limit_per_5():
        try:
            comment.insert_reply(articleid=articleid,
                                 commentid=commentid,
                                 content=content,
                                 ipaddr=ipaddr)
            # 评论成功后,同步更新credit表明细,user表积分和article表回复数
            Credit().insert_detail(type='回复评论', target=articleid, credit=2)
            User().update_credit(2)
            Article().update_replycount(articleid)
            return 'reply-pass'
        except:
            return 'reply-fail'
    else:
        return 'reply-limit'
Exemple #2
0
def comment_manage():
    comment = Comment()
    result = comment.find_all_comment(0, 10)
    total = math.ceil(comment.get_total_count() / 10)
    return render_template('admin-comment.html',
                           result=result,
                           page=1,
                           total=total,
                           type='no')
Exemple #3
0
def comment_cl(page):
    start = (page - 1) * 10
    comment = Comment()
    result = comment.find_all_comment(start, 10)
    total = math.ceil(comment.get_total_count() / 10)
    return render_template('admin-blog.html',
                           result=result,
                           page=page,
                           total=total,
                           type='no')
Exemple #4
0
def delete_comment():
    commentid = request.form.get('commentid')
    comment = Comment()
    comment = comment.find_by_commentid(commentid)
    blogid = comment.blogid
    try:
        comment.delete_comment(commentid)
        Blog().reduce_blog_comment(blogid)
        return 'del-success'
    except:
        return 'del-fail'
Exemple #5
0
def read(articleid):
    try:
        # 数据格式:(Article, 'nickname')
        result = Article().find_by_id(articleid)
        if result is None:
            abort(404)
    except:
        abort(500)
    dict = {}
    for k, v in result[0].__dict__.items():
        if not k.startswith('_sa_instance_state'):
            dict[k] = v
    dict['nickname'] = result.nickname

    # 如果已经消耗过积分,不再截取文章内容
    payed = Credit().check_payed_article(articleid)
    position = 0
    if dict['credit'] != 0:
        if not payed:
            content = dict['content']
            temp = content[0:int(len(content) / 2)]
            # 找到一个闭合标签
            position = temp.rindex('</p>') + 4
            dict['content'] = temp[0:position]
            # print(dict)
    Article().update_read_count(articleid)  # 阅读次数+1

    # 是否收藏
    is_favorited = Favorite().check_favorite(articleid)

    # 获取当前文章的上一篇和下一篇
    prev_next = Article().find_prev_next_by_id(articleid)

    # 显示当前文章评论信息
    comment_user = Comment().find_limit_with_user(articleid, 0, 50)

    # 对应新的模板文件——article-base.html
    comment_list = Comment().get_comment_user_list(articleid, 0, 10)

    # 原始评论总页数
    count = Comment().get_count_by_article(articleid)
    total = math.ceil(count / 10)

    # return render_template('article-base.html', result=result)
    # 评论有分页,回复已做好,最终模样,点赞、反对、隐藏 功能俱全
    return render_template('article-base.html',
                           article=dict,
                           position=position,
                           payed=payed,
                           is_favorited=is_favorited,
                           prev_next=prev_next,
                           comment_list=comment_list,
                           total=total)
Exemple #6
0
def delc():
    commentid = request.form.get('commentid')
    userid = request.form.get('userid')
    blogid = request.form.get('blogid')
    comment = Comment()
    if session.get('userid') == userid or session.get('role') == 'admin':
        try:
            comment.delete_comment(commentid=commentid)
            Blog().reduce_blog_comment(blogid)
            return 'del-success'
        except:
            return 'del-fail'
    else:
        return 'del-fail'
Exemple #7
0
def reply():
    commentid = request.form.get('commentid')
    blogid = request.form.get('blogid')
    content = request.form.get('content')

    if len(content) > 530:
        return 'len-error'

    comment = Comment()
    blog = Blog()
    credit = Credit()
    if session.get('ban') == 1:
        return 'comment-banned'
    if not comment.check_limit_comment():
        try:
            comment.insert_reply(blogid=blogid,
                                 commentid=commentid,
                                 content=content)
            blog.update_blog(blogid)
            credit.insert_exp(type='评论', exp=2)
            Users().update_exp(2)
            return 'add-success'
        except:
            return 'add-fail'
    else:
        comment.insert_reply(blogid=blogid,
                             commentid=commentid,
                             content=content)
        blog.update_blog(blogid)
        return 'add-success'
Exemple #8
0
def addc():
    blogid = request.form.get('blogid')
    content = request.form.get('content')
    content = content.replace('\n', '<br/>')
    print(content)
    if len(content) > 530:
        return 'len-error'
    blog = Blog()
    comment = Comment()
    credit = Credit()
    if session.get('ban') == '1':
        return 'comment-banned'
    if not comment.check_limit_comment():
        try:
            comment.insert_comment(blogid, content)
            blog.update_blog(blogid)
            credit.insert_exp(type='评论', exp=2)
            Users().update_exp(2)
            return 'add-success'
        except:
            return 'add-fail'
    else:
        comment.insert_comment(blogid, content)
        blog.update_blog(blogid)
        return 'add-success'
Exemple #9
0
def add():
    articleid = request.form.get('articleid')
    content = request.form.get('content').strip()
    ipaddr = request.remote_addr

    # 对评论内容进行简单检验
    if len(content) < 5 or len(content) > 1000:
        return 'content-invalid'
    comment = Comment()
    if not comment.check_limit_per_5():
        # try:
        comment.insert_comment(articleid, content, ipaddr)
        # 评论成功后,更新积分明细和剩余积分,以及文章回复数量
        Credit().insert_detail(type='添加评论', target=articleid, credit=2)
        User().update_credit(2)
        Article().update_replycount(articleid)
        return 'add-pass'
    # except:
    #     return 'add-fail'
    else:
        return 'add-limit'
Exemple #10
0
def do_opinion():
    commentid = request.form.get('commentid')
    type = int(request.form.get('type'))
    ipaddr = request.remote_addr

    # 判断是否已点赞/反对
    opinion = Opinion()
    is_checked = opinion.check_opinion(commentid, ipaddr)
    if is_checked:
        return 'already-opinion'
    else:
        opinion.insert_opinion(commentid, type, ipaddr)
        Comment().update_agree_oppose(commentid, type)
        return 'opinion-pass'
Exemple #11
0
def addlike():
    commentid = request.form.get('commentid')
    like = Likes()
    credit = Credit()
    if like.find_like(commentid=commentid):
        return 'have-liked'
    if not like.check_limit_like():
        comment = Comment().find_by_commentid(commentid)
        like.insert_like(commentid=commentid)
        credit.insert_exp_user(type='点赞', exp=1, userid=comment.userid)
        Users().update_like_exp(exp=1, userid=comment.userid)
        return 'like-success'
    else:
        like.insert_like(commentid=commentid)
        return 'like-success'
Exemple #12
0
def read(blogid):
    try:
        result = Blog().find_by_id(blogid)
        if result is None:
            abort(404)
    except:
        abort(404)

    is_favorite = Favorite().check_favorite(blogid)

    # 显示评论
    comment_user = Comment().find_comment_with_user(blogid, 0, 50)

    level1 = int(result.exp / 100)

    type = result[0].type

    return render_template('blog.html',
                           result=result,
                           is_favorite=is_favorite,
                           comment_user=comment_user,
                           level1=level1,
                           type=type)
Exemple #13
0
def comment_hide(commentid):
    comment = Comment()
    res = comment.hide_comment(commentid)
    if res == 'Fail':
        return 'hide-limit'
    return 'hide-pass'
Exemple #14
0
def comment_page(articleid, page):
    start = (page - 1) * 10
    comment = Comment()
    list = comment.get_comment_user_list(articleid, start, 10)
    return jsonify(list)