Exemple #1
0
    def post(self):
        args = comment_post_parser.parse_args()
        user = User.verify_auth_token(args['token'])

        if not user:
            raise InvalidToken()

        dup_comment = Comment.query.filter_by(content=args['content']).first()
        if dup_comment and dup_comment.user_id == user.id:
            raise DuplicateInfo('评论重复')

        comment = Comment()
        comment.user_id = user.id
        comment.article_id = args['article_id']
        comment.content = args['content']

        db.session.add(comment)
        db.session.commit()

        return {'message': 'ok'}, 200
Exemple #2
0
def article(id):
    comment_form = CommentsCreateForm()
    article = db.session.query(Articles).filter(Articles.id == id).first()
    creator = db.session.query(User).filter(User.id == article.creator).first()
    comments = db.session.query(Comment).filter(
        Comment.article_id == id).all()  # список кометариев
    if comment_form.validate_on_submit():
        comment = Comment()
        comment.comment_creator = current_user.id
        comment.article_id = id
        comment.content = comment_form.text.data

        current_user.comment.append(comment)
        db.session.commit()
        return render_template("news_template.html",
                               article=article,
                               creator=creator,
                               comments=comments,
                               form=comment_form)
    return render_template("news_template.html",
                           article=article,
                           creator=creator,
                           comments=comments,
                           form=comment_form)