示例#1
0
def comment_list(page):
    per_page_data = 10
    if page is None:
        page = 1
    next_page = page + 1
    pre_page = page - 1
    data = Comment.comment_query(id=None,
                                 per_page=page,
                                 page_count=per_page_data)  #每页100条数据
    if int(Comment.query.count() / per_page_data) == 0:
        last_page = int(Comment.query.count() / per_page_data)
    else:
        last_page = int(Comment.query.count() / per_page_data) + 1
    comment = []
    for v in data:
        comment.append({
            'id': v[0],
            'user_name': v[1],
            'movie_title': v[2],
            'content': v[3],
            'addtime': v[4],
            'face': v[5]
        })

    return render_template('admin/comment_list.html',
                           comment=comment,
                           last_page=last_page,
                           page=page,
                           next_page=next_page,
                           pre_page=pre_page)
示例#2
0
def play(id,page):
    movie=Movie.query.filter_by(id=id).first()
    if movie:
        movie.playnum=int(movie.playnum)+1
        Movie.add_comment_or_play(movie)
        form=AddComment()
        if form.validate_on_submit():
            if not session['user_id']:
                return redirect(url_for('home.login'))
            data=form.data
            if data['content']:
                comment=Comment(
                    user_id=session['user_id'],
                    movie_id=id,
                    addtime=datetime.datetime.now(),
                    content=data['content']
                )
                if Comment.addcomment(comment):
                    flash("添加评论成功!",'ok')
                    movie.commentnum=int(movie.commentnum)+1
                    Movie.add_comment_or_play(movie)
                    return redirect(url_for('home.play',id=id,page=page))
        shoucang=AddMoviecol()
        if shoucang.validate_on_submit():
            if not Moviecol.query.filter_by(user_id=session['user_id'],movie_id=id).count():
                if Moviecol.moviecol_add(session['user_id'],id):
                    flash("收藏成功!",'ok')
                    return redirect(url_for('home.play',id=id,page=page))
            else:
                if Moviecol.moviecol_del_by_user(session['user_id'],id):
                    flash("取消收藏!",'err')
                    return redirect(url_for('home.play',id=id,page=page))
        pre_page_date=20     #每页20条数据
        comment_count=Comment.query.filter_by(movie_id=id).count() #评论总数
        page_data=Movie.query.filter_by(id=id).first_or_404()
        tag=Tag.query.filter_by(id=page_data.tag_id).first_or_404()
        tag_name=tag.name
        if page is None:
            page=1
        next_page=page+1
        pre_page=page-1
        data=Comment.comment_query(id=id,per_page=page,page_count=pre_page_date)
        if int(comment_count/pre_page_date)==0:
            last_page=int(comment_count/pre_page_date)
        else:
            last_page=int(comment_count/pre_page_date)+1
        comment=[]
        for v in data:
            comment.append({
                'id':v[0],
                'user_name':v[1],
                'movie_title':v[2],
                'content':v[3],
                'addtime':v[4],
                'face':v[5]
            })
    return render_template('home/play.html',shoucang=shoucang,id=id,form=form,page_data=page_data,tag_name=tag_name,comment=comment,last_page=last_page,page=page,next_page=next_page,pre_page=pre_page,comment_count=comment_count)