def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.datetime.now() db.session.add(new_comment) db.session.commit() post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() recent, top_tags = sidebar_data() return render_template( 'post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form )
def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.datetime.now() db.session.add(new_comment) db.session.commit() post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() recent, top_tags = sidebar_data() return render_template('post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form)
def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.datetime.now() db.session.add(new_comment) db.session.commit() form.name.data = None form.text.data = None post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() recent, top_tags = sidebar_data() if request.method == 'POST': return redirect(url_for('blog.post', post_id=post_id)) else: return render_template('blog/post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form)
def post(post_id, page=1): form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): comment = Comment() comment.name = form.name.data comment.text = form.text.data comment.post_id = post_id comment.date = datetime.datetime.now() db.session.add(comment) db.session.commit() return redirect(url_for('post', post_id=post.id)) post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc() ).paginate(page, 10) recent, top_tags = sidebar_data() return render_template( 'post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form )
def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.now() db.session.add(new_comment) db.session.commit() return redirect(url_for('.post', post_id=post_id)) post = Post.query.get_or_404(post_id) # 添加阅读量 post.read = post.read + 1 db.session.add(post) db.session.commit() tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() # 是否有编辑权限 permission = Permission(UserNeed(post.user.id)) is_edit = permission.can() or admin_permission.can() if g.is_login: form.name.data = current_user.username return render_template('post.html', post=post, tags=tags, is_edit=is_edit, comments=comments, form=form)
def get_post(post_id): form = CommentForm() post = Post.query.get_or_404(post_id) if g.current_user and form.validate_on_submit(): comment = Comment(form.text.data) comment.post_id = post_id comment.user_id = g.current_user.id comment.date = datetime.datetime.now() db.session.add(comment) db.session.commit() form.text.data = "" return render_template('post.html', post=post, form=form)
def post(post_id): form = CommentForm() post = Post.objects(id=post_id).get_or_404() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.date = datetime.datetime.now() post.comments.append(new_comment) post.save() tags = post.tags comments = post.comments return with_sidebar_render('post.html', post=post, tags=tags, comments=comments, form=form)