def post(post_id): # get_or_404() method gets the post with the post_id and if it doesn't exist it returns a 404 error ( # page doesn't exist) view_post = Post.query.get_or_404(post_id) form = CommentForm() if form.validate_on_submit(): comment = Comment(body=form.body.data, post=view_post, author=current_user._get_current_object() ) # current_user._get_current_object() db.session.add(comment) db.session.commit() flash('Your comment has been added', 'success') return redirect(url_for('.post', post_id=view_post.id, page=-1)) page = request.args.get('page', 1, type=int) if page == -1: page = (view_post.comments.count() - 1) // current_app.config['FLASKY_COMMENTS_PER_PAGE'] + 1 pagination = view_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('post.html', title=view_post.title, post=view_post, form=form, comments=comments, pagination=pagination)
def post(post_id): page = request.args.get('page', 1, type=int) post = Post.query.get_or_404(post_id) comments = Comment.query\ .filter_by( post=post )\ .order_by( Comment.date_posted.desc() )\ .paginate( per_page=6, page=page ) form = CommentForm() if form.validate_on_submit(): new_comment = Comment(content=form.content.data, post_id=post.id, user_id=current_user.id) db.session.add(new_comment) db.session.commit() flash('Comentário adicionado', 'success') 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 post(post_id): post = Post.query.filter_by(id=post_id).first() post_id = post.id category = post.category comments = PostComment.query.filter( PostComment.post_id == post_id).order_by(PostComment.date_posted.asc()) posts = (Post.query.filter(Post.id != post_id, Post.category == category, Post.published == True).order_by( Post.date_posted.desc()).limit(6)) form = CommentForm() if form.validate_on_submit(): comment = PostComment(content=form.content.data, user=current_user, post_id=post.id) db.session.add(comment) db.session.commit() flash("Your comment has been added!", "success") return redirect( url_for("posts.postslug", _anchor="commentsection", post_slug=post.slug)) return render_template( "post.html", form=form, title=post.title, shortdesc=post.shortdesc, post=post, posts=posts, comments=comments, )
def comment(post_id): post = Post.query.get_or_404(post_id) form = CommentForm(request.form) if form.validate_on_submit(): comment = Comment(content=form.content.data, author=current_user, post=post) db.session.add(comment) db.session.commit() return Response(status=200) return Response(status=500)
def post(post_id): post = Post.query.get_or_404(post_id) comments = Comment.query.filter_by(post=post).order_by(Comment.date_posted.desc()) form = CommentForm() if form.validate_on_submit() and current_user: comment = Comment(content=form.content.data, author=current_user, post=post) db.session.add(comment) db.session.commit() flash('Comment has been created', 'success') 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 new_post_comment(post_id): form = CommentForm() post = Post.query.get_or_404(post_id) if form.validate_on_submit(): comment = Comment(content=form.content.data, com_author=current_user, post=post) Comment.save(comment) flash('Your comment has been posted!', 'success') return redirect(url_for('main.home')) return render_template('new_post_comment.html', title='New comment', form=form, post=post)
def comment(post_id): post = Post.query.filter_by(id=post_id).first() comments = Comment.query.order_by(Comment.id.desc()) form1 = CommentForm() if form1.validate_on_submit(): post_comment = Comment(comment=post, comment_author=current_user, content=form1.comment.data) db.session.add(post_comment) db.session.commit() return redirect(url_for('main.home')) return render_template('comment.html', form1=form1, post=post, comments=comments)
def post(post_id): form = CommentForm() post = Pitch.query.get_or_404(post_id) comments = Comment.query.all() if form.validate_on_submit(): comment = Comment(comment=form.comment.data, pitch_id=post.id) db.session.add(comment) db.session.commit() return redirect(url_for('posts.post', post_id=post.id)) return render_template('post.html', title=post.title, post=post, comments=comments, form=form)
def post(post_id): form = CommentForm() post = Post.query.get_or_404(post_id) comments = Comment.query.filter_by(post_id=post_id).all() if form.validate_on_submit(): comment = Comment(name=form.username.data, content=form.content.data, post_id=post.id) db.session.add(comment) db.session.commit() flash('Your comment was added!', 'success') return redirect(url_for('post', post_id=post.id)) return render_template('portfolio.html', post=post, title=post.title, form=form, comments=comments)
def post(post_id): post = Post.query.get_or_404(post_id) comments = Comment.query.filter_by(post_id=post_id).\ order_by(Comment.created_date.desc()).all() form = CommentForm() if form.validate_on_submit(): # if current_user.is_authenticated: # user = True comment = Comment(content=form.content.data, user= True if current_user.is_authenticated else False, post_id=post_id) db.session.add(comment) db.session.commit() flash('Comment posted', 'success') redirect('posts.post') return render_template('post.html', title=post.title, post=post, form=form, comments=comments) #, comments=comments)
def new_comment(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): comment = Comment(content=form.content.data, article=post, author=current_user) db.session.add(comment) db.session.commit() flash('Your comment has been added to the post', 'success') #return redirect(url_for('posts.post', post_id=post.id)) return redirect(url_for('posts.post', post_id=post.id)) #return redirect(url_for('posts.post', post_id=post.id, 'comments', comment_id=comment.id)) return render_template('create_comment.html', title='Comment Post', form=form, post_id=post_id, all_posts=all_posts())
def post(post_id): form = CommentForm() post_selected = Post.query.get_or_404(post_id) if request.method == 'GET': comments = PostMetadata.query.filter(post_id == post_id).all() like_count, dislike_count=getEmotionCount(comments) return render_template('comments.html', form=form, title=post_selected.title, post=post_selected, comments=comments, like_count=like_count, dislike_count=dislike_count ,today=datetime.now()) else: save_comment(post_selected) return redirect(url_for('posts.post', post_id=post_id))
def post(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() comments = Comment.query.filter_by(post_id=post_id).all() if form.validate_on_submit(): if not current_user.is_authenticated: flash('Only user can leave a comment', 'danger') return redirect(url_for('posts.post', post_id=post_id)) comment = Comment(content=form.content.data, author=current_user, post_id=post_id) db.session.add(comment) db.session.commit() flash('Your comment has been created!', 'success') return redirect(url_for('posts.post', post_id=post_id)) return render_template('post.html', title=post.title, post=post, comments=comments, form=form)
def post(post_id): post = Post.query.get_or_404(post_id) 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.', 'danger') return redirect(url_for('.post', 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.date_comment.asc()).paginate( page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'], error_out=False) comments = pagination.items return render_template('post.html', posts=[post], form=form,comments=comments, pagination=pagination, title=post.title,post=post)
def post(post_id): sql = db.text("SELECT * FROM Post WHERE id={}".format(post_id)) post = db.session.query(Post).from_statement(sql).first() form = CommentForm() comment = Comment.query.filter_by(post_id=post_id).all() #post = Post.query.get_or_404(post_id) return render_template('post.html', title=post.title, post=post, comments=comment, form=form)
def save_comment(post): form = CommentForm() if form.commentimg.data: commentimg_file = save_commentimg(form.commentimg.data) else: commentimg_file = None postcomment = PostMetadata(post_comment=form.comment.data, comment_img=commentimg_file, author_comment=current_user, posts=post) db.session.add(postcomment) db.session.commit()
def post(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() form2 = ReactForm() form3 = DisReactForm() reactis = React.query.filter_by(author3=current_user, author4=post).all() reactis2 = React.query.filter_by(author3=current_user, author4=post).first() postreactis = React.query.filter_by(author4=post).all() print(reactis2) comments = Comment.query.filter_by(post_id=post_id)\ .order_by(Comment.date_comment.desc()).all() if form.submit1.data and form.validate(): pos = Comment(comment_content=form.comment.data, author1=current_user, author2=post) db.session.add(pos) db.session.commit() flash('Thank you for the comment', 'success') return redirect(url_for('posts.post', post_id=post_id)) if form2.submit2.data: rct = React(author3=current_user, author4=post) db.session.add(rct) db.session.commit() return redirect(url_for('posts.post', post_id=post_id)) if form3.submit3.data: db.session.delete(reactis2) db.session.commit() return redirect(url_for('posts.post', post_id=post_id)) return render_template('post.html', title=post.title, post=post, form=form, commentsno=len(comments), comments=comments, form3=form3, form2=form2, postreactis=len(postreactis), reactis=len(reactis))
def moderate(): form = CommentForm() page = request.args.get('page', 1, type=int) pagination = Comment.query.order_by(Comment.timestamp.asc()).paginate( page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'], error_out=False) comments = pagination.items print(comments) return render_template('moderate_comments.html', comments=comments, pagination=pagination, page=page, form=form)
def post(post_id): latest_posts = Post.query.order_by(Post.date_posted.desc()).limit(6).all() top_rated_posts = Post.query.outerjoin(Upvote_association).group_by( Post.id).order_by(func.count().desc()).limit(6).all() post = Post.query.get_or_404(post_id) comments = Comment.query.filter_by(post=post) print('Hey') for posts in top_rated_posts: print(posts) form = CommentForm() if form.validate_on_submit(): comment = Comment(content=form.content.data, author=current_user, post=post) db.session.add(comment) db.session.commit() return Response(status=200) return render_template('post.html', title=post.title, post=post, form=form, comments=comments, top_rated_posts=top_rated_posts, latest_posts=latest_posts)