예제 #1
0
def post(post_id):
    page = request.args.get('page', 1, type=int)
    post = Post.query.get_or_404(post_id)
    #Post.query.paginate(page = page, per_page = 10)
    comments = Comment.query.filter_by(post_id=post_id)
    comments = comments.paginate(page=page, per_page=20)
    #comments = Comment.query.paginate(page = page, per_page = 20)
    form = CommentForm()

    if form.validate_on_submit():

        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('home'))

    return render_template('post.html',
                           title=post.title,
                           post=post,
                           comments=comments,
                           form=form,
                           legend='Comments')
예제 #2
0
def post(post_id):
    """View function for post page"""

    # Form object: `Comment`
    form = CommentForm()
    # form.validate_on_submit() will be true and return the
    # data object to form instance from user enter,
    # when the HTTP request is POST
    if form.validate_on_submit():
        new_comment = Comment(id=str(uuid4()), name=form.name.data)
        new_comment.text = form.text.data
        new_comment.date = datetime.now()
        new_comment.post_id = post_id
        db.session.add(new_comment)
        db.session.commit()

    post = db.session.query(Post).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,
                           form=form,
                           recent=recent,
                           top_tags=top_tags)
예제 #3
0
def play_movie(movie_id):
    form = CommentForm()
    post = Movie.query.get_or_404(movie_id)
    credit = Credits(movie_id=movie_id)
    db.session.add(credit)
    db.session.commit()
    rem_movie = get_recommendations(movie_id)
    if form.validate_on_submit():
        comm = Comment(content=form.content.data,
                       movie_id=movie_id,
                       author_user=current_user)
        db.session.add(comm)
        db.session.commit()
        flash('Your comment has been posted!', 'success')
        return redirect(url_for('play_movie', movie_id=movie_id))
    comm = Comment.query.filter_by(movie_id=movie_id).order_by(
        Comment.date_posted.desc())
    usrr = User.query.all()
    com_total = comm.count()
    movie = Movie.query.all()
    return render_template('play_movie.html',
                           com_total=com_total,
                           title=post.title,
                           usrr=usrr,
                           post=post,
                           comm=comm,
                           rem_movie=rem_movie,
                           movie=movie,
                           form=form)
예제 #4
0
def post(post_id):
    """View function for post page"""

    #form object:comment
    form = CommentForm()
    #当HTTP请求是POST时,提交验证通过并把用户输入返回
    if form.validate_on_submit():
        new_comment = Comment(id=str(uuid4()), name=form.name.data)
        new_comment.text = form.text.data
        new_comment.date = datetime.datetime.now()
        new_comment.post_id = post_id
        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,
                           form=form,
                           recent=recent,
                           top_tags=top_tags)
예제 #5
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    comments = Comment.query.filter_by(post_id_comm=post_id).all()
    likes = Like.query.filter_by(post_id=post_id,
                                 username=current_user.username)
    # likes_2 = Like.query.filter_by(post_id=post_id, username=current_user.username)
    number_of_likes = Like.query.filter_by(post_id=post_id).count()

    form = CommentForm()
    if request.method == 'GET':
        post.view += 1
        db.session.commit()

    if request.method == 'POST':
        if form.validate_on_submit():
            new_comment = Comment(text_comment=form.comment_text.data,
                                  post_id_comm=post_id,
                                  user_id_comm=current_user.id)
            db.session.add(new_comment)
            db.session.commit()
            return redirect(url_for('home'))

    return render_template('post.html',
                           title=post.title,
                           post=post,
                           form=form,
                           comments=comments,
                           likes=likes,
                           number_of_likes=number_of_likes)
예제 #6
0
def comments(post_id):
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data, user_id=current_user.id, post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        flash('Commented!', 'success')
        return redirect(url_for('comments',post_id=post_id))
    comments = Comment.query.filter_by(post_id=post_id).all()
    return render_template('comments.html', comments=comments,legend='Comments',form=form)
예제 #7
0
def new_comment(post_id):
    post = Post.query.get(post_id)
    form = CommentForm()
    if True:
        comment = Comment(content=form.content.data,
                          author=current_user,
                          post_id=post.id)
        db.session.add(comment)
        db.session.commit()
        form = CommentForm()
        return redirect(url_for('post', post_id=post.id))
예제 #8
0
def comment_post(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    user = current_user
    if form.validate_on_submit():
        comment = Comment(content=form.content.data, post_id=post.id, user_id=current_user.username, image=user.image_file)
        db.session.add(comment)
        db.session.commit()
        flash("Comentario añadido", "success")
        return redirect(url_for("post", post_id=post.id))
    return render_template("comment_post.html", title="Opina", form=form)
예제 #9
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    comments = Comment.query.all()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data, author=current_user)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('post.html', post=post, form=form, comments=comments)
예제 #10
0
def post_display(post_id):
	test_id = post_id
	post = Post.query.get(int(post_id))
	coms = post.comments
	form = CommentForm()
	x = current_user.id
	if form.validate_on_submit():
		comment = Comment(text=form.text.data, user = x)
		db.session.add(comment)
		comment.posted_on.append(post)
		db.session.commit()
		flash('Comment added succesfully', 'success')
		return redirect(url_for('home'))
	return render_template('display_post.html', title='post.id', post = post, comments = coms, form = form)
예제 #11
0
def comment_post(post_id):

    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data, commented_post=Post.query.get(post_id), commenter=current_user)
        db.session.add(comment)
        db.session.commit()

        flash('Your comment have been created!', 'success')
        
        return redirect(url_for('post', post_id=post.id))

    return render_template('comment_post.html', title='Comment Post', form=form, post=post)
예제 #12
0
def comment_post(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data,
                          post=post,
                          creator=current_user)
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for("post", post_id=post.id))
    return render_template("comment.html",
                           post=post,
                           legend="Create Comment",
                           form=form)
예제 #13
0
def update_comment(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    if comment.author != current_user:
        abort(403)
    form = CommentForm()
    if form.validate_on_submit():
        comment.content = form.content.data
        db.session.commit()
        flash('Your comment has been updated!', 'success')
        return redirect(url_for('home'))
    elif request.method == 'GET':
        form.content.data = comment.content
    return render_template('new_comment.html',
                           form=form,
                           legend='Update Comment')
예제 #14
0
def picture(picture_id):         # , folder_id)???
    picture = Picture.query.get_or_404(picture_id)
    form = CommentForm()
    if form.validate_on_submit():
        if current_user.is_authenticated: # you can only comment if you're logged in
            comment = Comment(content=form.content.data, user=current_user, picture=picture)
            db.session.add(comment)
            db.session.commit()
            flash('Your comment has been created!', 'success')
            return redirect(f'/picture/{picture.id}')
        else:
            flash('You are not logged in. You need to be logged in to be able to comment!', 'danger')
    # loading comments in the reverse order of insertion
    comments = Comment.query.filter_by(picture_id=picture_id).order_by(Comment.date_posted.desc()).all()
    return render_template('picture.html', title=f'picture-{picture.image_file}', picture=picture, form=form, comments=comments)
예제 #15
0
def show_post(post_id):
    post = Post.query.get_or_404(post_id)
    page = request.args.get("page", 1, type=int)
    comment_per_page = current_app.config["BLOG_COMMENT_PER_PAGE"]
    # 得到该文章的对应评论的第一页(没通过审核的评论不显示)
    pagination = Comment.query.with_parent(post).filter_by(reviewed=True) \
     .order_by(Comment.timestamp.asc()).paginate(page, per_page=comment_per_page)
    comments = pagination.items

    if current_user.is_authenticated:  # 用户已登录,则用管路员评论表单
        form = AdminCommentForm()
        form.author.data = current_user.name
        form.email.data = current_app.config["BLOG_EMAIL"]
        form.site.data = url_for(".index")
        from_admin = True  # 管理员评论默认通过审核
        reviewed = True

    else:
        form = CommentForm()
        from_admin = False
        reviewed = False

    # 提交评论或者回复表单后
    if form.validate_on_submit():
        author = form.author.data
        email = form.email.data
        site = form.site.data
        body = form.body.data

        comment = Comment(author=author,
                          email=email,
                          site=site,
                          body=body,
                          from_admin=from_admin,
                          reviewed=reviewed,
                          post=post)
        # 如果URL中reply参数存在,则说明是回复
        # 被回复的评论的id(这里可以是访客回复管理员消息,也可以是管理员回复游客消息)
        replied_id = request.args.get("reply")
        if replied_id:
            replied_comment = Comment.query.get_or_404(replied_id)
            comment.replied = replied_comment
            send_new_reply_email(replied_comment)
        db.session.add(comment)
        db.session.commit()

        # 不同身份用户评论后,页面闪现出的提示消息也略有不同
        if current_user.is_authenticated:  # 管理员回复就免去了向自己发送邮件的过程
            flash('成功回复!', 'success')
        else:
            flash('感谢你的回复,管理员审核后将被发布!', 'info')
            # 当有游客对某篇文章进行评论/回复时,通知管理员审核
            send_new_comment_email(post)
        return redirect(url_for(".show_post", post_id=post_id))

    return render_template("blog/post.html",
                           post=post,
                           pagination=pagination,
                           form=form,
                           comments=comments)
예제 #16
0
def create_comment(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            author = current_user.username
        else:
            author = 'Anonymous'
        comment = Comment(content=form.content.data,
                          author=author,
                          post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been created!', 'success')
        return redirect(url_for('post', post_id=post.id))
    return render_template('create_comment.html', form=form, legend="New Comment")
예제 #17
0
def comment(post_id, username):
    post = Post.query.get_or_404(post_id)
    #print(post)
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(replyto=username,
                          content=form.content.data,
                          post=post,
                          author=current_user)
        #print(comment.replyto)
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('post', post_id=post.id))
    return render_template('comment.html',
                           title='comment',
                           form=form,
                           replyto=username)
예제 #18
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    comments = Comment.query.filter_by(post_id=post.id).all()
    form = CommentForm()
    return render_template('post.html',
                           title=post.title,
                           post=post,
                           comments=comments,
                           form=form)
예제 #19
0
def sermon(sermon_id):
    page = request.args.get('page', 1, type=int)
    sermons = Sermon.query.order_by(Sermon.date_posted.desc()).paginate(
        page=page, per_page=5)
    sermon = Sermon.query.get_or_404(sermon_id)
    comments = Comment.query.order_by(Comment.date_posted.desc()).all()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(comment=form.message.data, author=current_user)
        db.session.add(comment)
        db.session.commit()
        flash('Comment posted!', 'success')
        return redirect(url_for('sermon', sermon_id=sermon.id))
    return render_template('main/single_vid.html',
                           title=sermon.title,
                           form=form,
                           sermon=sermon,
                           sermons=sermons,
                           comments=comments)
예제 #20
0
def post(post_id):
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page,
                                                                  per_page=5)
    post = Post.query.get_or_404(post_id)
    comments = Comment.query.order_by(Comment.date_posted.desc()).all()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(comment=form.message.data, author=current_user)
        db.session.add(comment)
        db.session.commit()
        flash('Comment posted!', 'success')
        return redirect(url_for('post', post_id=post.id))
    return render_template('main/single.html',
                           title=post.title,
                           form=form,
                           post=post,
                           posts=posts,
                           comments=comments)
예제 #21
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:  # you can only comment if you're logged in
            # Check if is a comment from a post or from another comment
            comment_id = None if form.comment_id.data == '' else int(
                form.comment_id.data)
            comment = Comment(content=form.content.data,
                              user=current_user,
                              post=post,
                              comment_id=comment_id)
            db.session.add(comment)
            db.session.commit()
            flash('Your post has been created!', 'success')
            return redirect(f'/post/{post.id}')
        else:
            flash(
                'You are not logged in. You need to be logged in to be able to comment!',
                'danger')
    return render_template('post.html', title=post.title, post=post, form=form)