def post(self): data = request.get_json(force=True) comment_id = data.get("id") if not g.user.is_admin: return fail_msg(msg='非管理员不能删除评论!') comment = Comment.query.filter_by(id=comment_id).first() if not comment: return fail_msg(msg='该评论不存在!') db.session.delete(comment) db.session.commit() return success_msg
def post(self): data = request.get_json(force=True) article_id = data.get("id") if not g.user.is_admin: return fail_msg(msg='非管理员不能删除文章!') article = Article.query.filter_by(id=article_id).first() if not article: return fail_msg(msg='该文章不存在!') db.session.delete(article) db.session.commit() return success_msg
def post(self): data = request.get_json(force=True) article_id = data.get("id") enable_comment = data.get("enable_comment") if not g.user.is_admin: return fail_msg(msg='非管理员不能进行相关设置!') article = Article.query.filter_by(id=article_id).first() if not article: return fail_msg(msg='该文章不存在!') article.can_have_comments = enable_comment db.session.commit() return success_msg
def post(self): data = request.get_json(force=True) title = data.get("title") content = data.get("content") author_id = g.user.id if not title: return fail_msg(msg='标题不能为空!') if not g.user.is_admin: return fail_msg(msg='非管理员不能发布文章!') article = Article(title=title, content=content, author_id=author_id) db.session.add(article) db.session.commit() return success_msg
def post(self): data = request.get_json(force=True) username = data.get("username") password = data.get("password") email = data.get("email") if not username or not password or not email: return fail_msg(msg="输入错误!") if User.query.filter_by( username=username).first() or User.query.filter_by( email=email).first(): return fail_msg(msg="用户名或邮箱已注册!") user = User(username=username, email=email) user.hash_password(password) db.session.add(user) db.session.commit() return success_msg
def post(self): data = request.get_json(force=True) content = data.get("content") article_id = data.get("article_id") author_id = g.user.id if not content: return fail_msg(msg='内容不能为空!') if not Article.query.filter_by(article_id=article_id).first(): return fail_msg(msg='该文章不存在!') if Article.query.filter_by(article_id=article_id, can_have_comments=False).first(): return fail_msg(msg='该文章不能被评论!') article = Comment(content=content, author_id=author_id, article_id=article_id) db.session.add(article) db.session.commit() return success_msg
def post(self): data = request.get_json(force=True) article_id = data.get("id") article = Article.query.filter_by(id=article_id).first() if not article: return fail_msg(msg="该文章不存在!") output = {} output['article'] = to_dict(article.__dict__.copy()) if article.comments: output['comments'] = { to_dict(comment.__dict__.copy()) for comment in article.comments } else: output['comments'] = {} return jsonify(output)