def postn(post_id): post = Post.query.get_or_404(post_id) comment = Comment form = CommentForm() if form.validate_on_submit(): comment = Comment(body=form.body.data, post=post, Protagonist=current_user._get_current_object()) db.session.add(comment) db.session.commit() flash('Your comment has been published.', 'success') return redirect(url_for('posts.postn', post_id=post.id, page=-1)) page = request.args.get('page', 1, type=int) if page == -1: page = (post.comments.count() - 1) // \ current_app.config['FLASKY_COMMENTS_PER_PAGE'] + 1 pagination = post.comments.order_by(Comment.timestamp.asc()).paginate( page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'], error_out=False) comments = pagination.items return render_template('posts/post.html', posts=[post], post=post, form=form, comments=comments, pagination=pagination, comment=comment, title=post.title)
def post(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() # author=current_user if 'user' in session and form.validate_on_submit(): com = Comment(body=form.body.data, post_id=post_id, comment=current_user, user_id=session['user_id']) db.session.add(com) db.session.commit() post.commentnum = +1 flash('Your comment has been published.') page = request.args.get('posts.post', 1, type=int) if page == 1: page = (post.comments.count() - 1) // current_app.config['FLASKY_COMMENTS_PER_PAGE'] + 1 pagination = post.comments.order_by( Comment.date_posted.asc()).paginate( page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'], error_out=False) comments = pagination.items return render_template('posts/post.html', title=post.title, post=post, form=form, comments=comments, pagination=pagination)
def post(post_id): post = Post.query.get_or_404(post_id) if post == None: return post page = request.args.get('page', 1, type=int) form = CommentForm() comments = Comment.query.filter_by(post=post)\ .order_by(Comment.date_posted.desc()) print("comments", file=sys.stdout) print(comments, file=sys.stdout) if form.validate_on_submit(): comment = Comment(body=form.body.data, post=post, author=current_user._get_current_object()) db.session.add(comment) db.session.commit() if post.author == current_user: flash('Your Comment is uploaded sucessfully.', 'success') else: notifiedWhenSomeoneCommented(post.author, current_user, comment) flash('Author is notified with your comment via Email.', 'info') return redirect(url_for('posts.post', post_id=post.id)) return render_template("post.html", title=post.title, post=post, form=form, comments=comments)
def comment(): form = CommentForm(request.form) print(request.form) if form.validate(): user = User.get(User.id == current_user.get_id()) comment_text = form.comment.data post_id = form.post_id.data result = user.comment(post_id, comment_text) return result return form.errors
def add_comment(): form = CommentForm() if form.validate_on_submit(): post = Post.objects(id=form.post_id.data).get() comment = Comment(text=form.comment_text.data, from_user=User.objects(id=current_user.id).get(), post=post) comment.save() Post.objects(id=form.post_id.data).update_one(push__comments=comment) return redirect(get_redirect_target())
def new_comment(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() if form.validate_on_submit(): comment = Comment(comment=form.comment.data, post_id = post_id ) db.session.add(comment) db.session.commit() flash('Comment has been added!', 'success') return redirect(url_for('posts.post', post_id=post.id)) return render_template('comment.html', title='Comment Here', form=form, legend='Comment Here')
def post(post_id): review= CommentForm() comments = Comment.query.all() post = Pitch.query.get_or_404(post_id) if review.validate_on_submit(): comment = Comment(body= review.comment.data,post_id=post.id ) db.session.add(comment) db.session.commit() flash('Your post has been created!','success') return redirect(url_for('posts.post',post_id=post.id)) return render_template('post.html',title = post.title, post=post,review=review, comments = comments )
def post(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() if form.validate_on_submit(): comment = Comment(content=form.content.data) db.session.add(comment) #db.session.commit() flash('Your comment has been posted!', 'success') return redirect(url_for('main.home')) return render_template('posted.html', title=post.title, post=post, form=form)
def new_comment(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() if form.validate_on_submit(): comment = Comment(comment=form.comment.data, fullname=form.name.data, author=current_user, post_id = post_id ) db.session.add(comment) db.session.commit() # comments = Comment.query.all() flash('You comment has been created!', 'success') return redirect(url_for('posts.post', post_id=post.id)) myposts = Post.query.order_by(Post.posted_date.desc()) return render_template('new-comment.html', title='New Comment', form=form, legend='New Comment', myposts=myposts)
def details(id): post = Post.query.filter_by(id=id).first_or_404() form = CommentForm() if form.validate_on_submit(): comment = Comment(body=form.body.data, post=post, author=current_user._get_current_object()) db.session.add(comment) db.session.commit() flash('Your comment has been published.') return redirect(url_for('posts.index')) return render_template('posts/details.html', title='Details', form=form, post=post)
def post(post_id): post = Post.query.get_or_404(post_id) comment_form = CommentForm() comment_reply_form = CommentReplyForm() if comment_form.validate(): comment = Comment(content=comment_form.comment.data, post_id=post.id, user=current_user) db.session.add(comment) db.session.commit() flash('New comment posted', 'success') return redirect(url_for('posts.post', post_id=post_id)) if comment_reply_form.validate(): print('posting a comment reply') parent_comment_id = comment_reply_form.parent_comment.data comment_reply = CommentReply(content=comment_reply_form.content.data, comment_id=parent_comment_id, user=current_user) db.session.add(comment_reply) db.session.commit() flash('Comment reply posted', 'success') return redirect(url_for('posts.post', post_id=post_id)) if post: comments = Comment.query.filter_by(post_id=post_id) comment_replies = {} for comment in comments: comment_replies[comment.id] = CommentReply.query.filter_by( comment_id=comment.id) print(comment_replies) return render_template('view_post.html', title=post.title, post=post, comment_form=comment_form, post_editable=True, show_comments=True, comments=comments, comment_reply_form=comment_reply_form, comment_replies=comment_replies)
def single_post(post_id): my_post = Post.objects(id=post_id).get() if not my_post: abort(404) form = CommentForm(post_id=post_id) return render_template('posts/single_post.html', page_title=my_post.title, post=my_post, comment_form=form)
def post(id): post = Post.query.get_or_404(id) form = CommentForm() if form.validate_on_submit(): language = guess_language(form.comment.data) if language == 'UNKNOWN' or len(language) > 5: language = '' comment = Comment(body=form.comment.data, post=post, author=current_user, language=language) db.session.add(comment) db.session.commit() flash(_('Your comment has been published.')) return redirect(url_for('posts.post', id=post.id)) comments = post.comments.order_by(Comment.timestamp.asc()) return render_template('post.html', post=post, form=form, comments=comments)
def index(): form = CommentForm() page = request.args.get('page', 1, type=int) posts = current_user.followed_posts().paginate( page, current_app.config['POSTS_PER_PAGE'], False) next_url = url_for('posts.index', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('posts.index', page=posts.prev_num) \ if posts.has_prev else None if form.validate_on_submit(): comment = Comment(body=form.body.data, post=post, author=current_user._get_current_object()) db.session.add(comment) db.session.commit() return render_template('posts/index.html', title='Followed Posts', posts=posts.items, form=form, next_url=next_url, prev_url=prev_url)
def comment_post(post_id): post = Post.query.get(post_id) form = CommentForm() comments = Comments(text=form.text.data) if request.method == 'POST': db.session.add(post) db.session.commit() flash('Your comment has been posted!', 'success') return redirect(url_for('posts.post', post_id=post.id)) return render_template('comment.html', title='Comments', post=post, form=form, comments=comments)
def post(post_id): review = CommentForm() comments = Comment.query.all() post = Pitch.query.get_or_404(post_id) if review.validate_on_submit(): # if review.picture.data: # picture_file = save_picture(review.picture.data) # if review.video.data: # video_file = save_video(review.video.data) picture_file = save_picture(review.picture.data) image = url_for('static', filename='images/' + picture_file) comment = Comment(body=review.comment.data, post_id=post.id, image_file=image) db.session.add(comment) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('posts.post', post_id=post.id)) return render_template('post.html', title=post.title, post=post, review=review, comments=comments)