Ejemplo n.º 1
0
def play(id, page=None):
    if page == None:
        page = 1
    form = CommentForm()
    # movie =Movie.query.get(int(id))
    movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id,
                                         Movie.id == int(id)).first()
    movie.playnum = movie.playnum + 1
    db.session.commit()
    # 分页查询
    page_data = Comment.query.join(User).join(Movie).filter(
        User.id == Comment.user_id, Movie.id == movie.id).order_by(
            Comment.addtime.desc()).paginate(page=page, per_page=5)
    if 'user' in session and form.validate_on_submit():
        data = form.data
        comment = Comment(content=data['content'],
                          movie_id=movie.id,
                          user_id=session['user_id'])
        db.session.add(comment)
        db.session.commit()
        flash('评论添加成功', 'ok')
        movie.commentnum = movie.commentnum + 1
        db.session.add(movie)
        db.session.commit()
        return redirect(url_for('home.play', page=page, id=id))

    return render_template("home/play.html",
                           movie=movie,
                           form=form,
                           page_data=page_data)
Ejemplo n.º 2
0
def addcomment():
    form = CommentForm()
    error = 'Sorry, Post Comments Error!'

    if form.validate_on_submit():
        comment = Comment(author_ip=request.environ['HTTP_X_FORWARDED_FOR'])
        form.populate_obj(comment)
        db.session.add(comment)
        post = Post.query.getpost_id(comment.post_id)
        post.comment_count += 1
        db.session.commit()
        return redirect(url_for('article', postid=comment.post_id))

    return render_template('/error.html', content=error)
Ejemplo n.º 3
0
def addcomment():
    form = CommentForm()
    error = 'Sorry, Post Comments Error!'

    if form.validate_on_submit():
        comment = Comment(author_ip=request.environ['HTTP_X_FORWARDED_FOR'])
        form.populate_obj(comment)
        db.session.add(comment)
        post = Post.query.getpost_id(comment.post_id)
        post.comment_count += 1
        db.session.commit()
        return redirect(url_for('article', postid=comment.post_id))

    return render_template('/error.html', content=error)
Ejemplo n.º 4
0
def post(id):
    # Detail 详情页
    post = Post.query.get_or_404(id)
    # 评论窗体
    form = CommentForm()
    # 保存评论
    if form.validate_on_submit():
        comment = Comment(body=form.body.data, post=post)
        db.session.add(comment)
        db.session.commit()

    return render_template('posts/detail.html',
                           title=post.title,
                           form=form,
                           post=post)
Ejemplo n.º 5
0
def show_post(post_id):
    form = CommentForm()
    requested_post = Post.query.get(post_id)
    if form.validate_on_submit():
        if not current_user.is_authenticated:
            flash("You need to login or register to comment.")
            return redirect(url_for("login"))
        new_comment = Comment(text=form.comment_text.data,
                              comment_author=current_user,
                              parent_post=requested_post)
        db.session.add(new_comment)
        db.session.commit()
    return render_template('post.html',
                           post=requested_post,
                           current_user=current_user,
                           form=form)