def play(id=None, page=1): movie = Movie.query.get_or_404(id) if not movie.play_num: movie.play_num = 0 movie.play_num += 1 # 获取当前用户的所有评论信息; count = Comment.query.filter_by(user_id=session.get('user_id')).count() commentsPageObj = Comment.query.filter_by( user_id=session.get('user_id')).filter_by(movie_id=id).paginate( page, per_page=app.config['PER_PAGE']) form = CommentForm() if form.validate_on_submit(): if session.get('user_id'): content = form.content.data.replace('<p>', '').replace('</p>', '') comment = Comment(content=content, movie_id=id, user_id=session.get('user_id')) if not movie.comment_num: movie.comment_num = Comment.query.filter_by( movie_id=id).count() movie.comment_num += 1 db.session.add(movie) db.session.add(comment) db.session.commit() flash("提交评论成功", category='ok') else: flash("提交评论失败, 请先登录", category='err') return redirect(url_for('home.play', id=id)) return render_template('home/play.html', app=app, movie=movie, count=count, form=form, commentsPageObj=commentsPageObj)
def play(id, page): form = CommentForm() movie = Movie.query.filter(Movie.id == int(id)).join(Tag).filter( Tag.id == Movie.tag_id).first_or_404() movie.playnum += 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id).order_by(Comment.addtime.desc()).paginate( page=page, per_page=20) 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) movie.commentnum += 1 db.session.commit() flash("添加评论成功", "ok") return redirect(url_for('home.play', id=movie.id, page=1)) db.session.commit() return render_template("home/play.html", movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): movie = (Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404()) movie.playnum += 1 form = CommentForm() if form.validate_on_submit(): data = form.data comment = Comment( content=data["content"], movie_id=movie.id, user_id=User.query.filter_by(email=session["user"]).first().id, ) db.session.add(comment) flash("评论成功", "ok") movie.commentnum += 1 db.session.add(movie) db.session.commit() if page is None: page = 1 page_data = (Comment.query.join(User).filter( Comment.user_id == User.id, Comment.movie_id == movie.id).order_by( Comment.add_time.desc()).paginate(page=page, per_page=10)) return render_template("home/play.html", movie=movie, form=form, page_data=page_data)
def play(id=None, page=1): form = CommentForm() if form.validate_on_submit(): print(form.content.data) # 提交评论必须登录; if session.get('user'): # 保存用户的评论信息 comment = Comment(content=form.content.data, movie_id=id, user_id=session.get('user_id')) db.session.add(comment) db.session.commit() flash("评论提交成功") else: flash("提交评论失败, 请先登录") return redirect(url_for('home.play', id=id), ) if not id: abort(404) if not page: page = 1 movie = Movie.query.get_or_404(id) # 获取当前电影的所有评论数量 count = Comment.query.filter_by(movie_id=id).count() # 获取评论信息(评论会员的头像, 名称, 电影名, 评论时间, 评论内容) commentsPageObj = Comment.query.filter_by(movie_id=id).paginate( page, per_page=app.config['PER_PAGE']) return render_template('home/play.html', movie=movie, count=count, commentsPageObj=commentsPageObj, form=form, app=app)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == id).first_or_404() movie.playnum = movie.playnum + 1 form = CommentForm() if page is None: page = 1 page_data = Comment.query.filter_by( movie_id=id).join(Movie).join(User).filter( Movie.id == Comment.movie_id, User.id == Comment.user_id).order_by( db.desc(Comment.addtime)).paginate(page=page, per_page=10) if 'user' in session and form.validate_on_submit(): data = form.data comment = Comment(content=data['input_content'], movie_id=movie.id, user_id=session['user_id']) movie.commentnum = movie.commentnum + 1 db.session.add(comment) db.session.add(movie) db.session.commit() return redirect(url_for('home.play', id=id, page=1)) db.session.add(movie) db.session.commit() return render_template("home/play.html", movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() form = CommentForm() movie.playnum = movie.playnum + 1 # 播放一次,播放数量+1 # 展示评论 if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, #User.id == session['user_id'] ).order_by(Comment.addtime.desc()).paginate(page=page, per_page=10) # 进行评论 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']) movie.commentnum = movie.commentnum + 1 db.session.add(comment) db.session.commit() db.session.add(movie) db.session.commit() flash('评论成功!', 'ok') return redirect(url_for('home.play', id=movie.id, page=1)) db.session.add(movie) # 放到if外面,不登录刷新也会增加播放次数 db.session.commit() return render_template('home/play.html', movie=movie, form=form, page_data=page_data)
def play(id, page=1): form = CommentForm() movie = Movie.query.filter_by(id=id).join(Tag).filter( Movie.tag_id == Tag.id ).first_or_404() movie.playnum += 1 db.session.add(movie) db.session.commit() comment_co = Comment.query.filter_by(movie_id=id).count() comment_list = Comment.query.filter_by(movie_id=id).join(User).filter( Comment.user_id == User.id ).order_by(Comment.addtime.desc()).paginate(page=page, per_page=8) if form.validate_on_submit(): data = form.content.data comment = Comment( content=data, movie_id=id, user_id=session['user_id'] ) movie.commentnum += 1 db.session.add(comment) db.session.add(movie) db.session.commit() flash('评论成功', 'ok') return redirect(url_for('home.play', id=movie.id, page=1)) return render_template('home/danmaku.html', comment_co=comment_co, movie=movie, form=form, comment_list=comment_list)
def video(id=None, page=None): movie = Movie.query.join(Tag).filter( Movie.id == id, Movie.tag_id == Tag.id).first_or_404() form = CommentForm() # 评论列表 if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.asc()).paginate(page=page, per_page=10) movie.playnum = movie.playnum + 1 if "user_id" in session and form.validate_on_submit(): data = form.data # TODO content 插入的时候需要过滤一些特殊字符 防止注入攻击之类的 comment = Comment(content=data["content"], movie_id=movie.id, user_id=session["user_id"]) db.session.add(comment) movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash("评论成功", "ok") return redirect(url_for("home.video", id=movie.id)) db.session.add(movie) db.session.commit() return render_template("home/video.html", movie=movie, form=form, page_data=page_data)
def artDesc(id=None, page=None): # art = Article.query.get_or_404(int(id)) art = Article.query.join(Cate).filter( Cate.id == Article.cate_id, Article.id == int(id)).first_or_404() art.viewNum = art.viewNum + 1 # 提交评论 commentForm = CommentForm() if "user" in session and commentForm.validate_on_submit(): data = commentForm.data comment = Comment(article_id=art.id, content=data['content'], user_id=session['id']) db.session.add(comment) db.session.commit() flash('评论成功!', 'okey') art.commentNum = art.commentNum + 1 db.session.add(art) db.session.commit() article = Article.query.join(Cate).filter(Article.cate_id == Cate.id, Article.id == int(id)).first() if page == None: page = 1 pageData = Comment.query.join(User).join(Article).filter( User.id == Comment.user_id, Article.id == article.id).order_by( Comment.addTime.desc()).paginate(page=page, per_page=10) return render_template('home/artdesc.html', art=art, form=commentForm, pageData=pageData)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=PAGE_COUNT) form = CommentForm() # 判断是否已经登录 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() commentnum = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).count() movie.commentnum = commentnum db.session.add(movie) db.session.commit() flash("添加评论成功!", "ok") return redirect(url_for("home.play", id=movie.id, page=1)) # 放在这里避免添加评论播放量+2 movie.playnum = movie.playnum + 1 db.session.add(movie) db.session.commit() return render_template('home/play.html', movie=movie, form=form, page_data=page_data)
def play(id=None, page=1): movie = Movie.query.get_or_404(int(id)) form = CommentForm() movie.playnum = movie.playnum + 1 if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == Comment.movie_id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) if 'user' in session and form.validate_on_submit(): data = form.data comment = Comment(content=data['comment'], movie_id=movie.id, user_id=session['user_id']) db.session.add(comment) db.session.commit() movie.commentnum = movie.commentnum + 1 flash("评论成功!", 'ok') return redirect(url_for("home.play", id=movie.id, page=page)) db.session.add(movie) db.session.commit() return render_template('home/play.html', movie=movie, form=form, page_data=page_data)
def article(id=None, page=None): article = db.session.query(Article).join(Tag).filter( Article.id == int(id), Tag.id == Article.tag_id).first_or_404() article.click_count = article.click_count + 1 form = CommentForm() if page is None: page = 1 page_data = db.session.query(Comment).join(Article).filter( Article.id == article.id).order_by(Comment.addtime.desc()).paginate( page=page, per_page=10) db.session.add(article) db.session.commit() if form.validate_on_submit(): data = form.data comment = Comment(content=data['content'], article_id=article.id, name=data['name']) db.session.add(comment) db.session.commit() article.commentnum = article.commentnum + 1 flash("发布评论成功!", 'ok') db.session.add(article) db.session.commit() return redirect(url_for('home.article', id=article.id, page=1)) return render_template('home/article.html', form=form, page_data=page_data, article=article)
def play(id=None, page=None): movie = Movie.query.join( Tag, and_(Movie.tag_id == Tag.id, Movie.id == int(id))).add_entity(Tag).first() if page is None: page = 1 page_data = Comment.query.join( Movie, Comment.movie_id == Movie.id).add_entity(Movie).join( User, Comment.user_id == User.id).add_entity(User).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) form = CommentForm() if "user" in session and form.validate_on_submit(): data = form.data comment = Comment(content=data['content'], movie_id=movie.Movie.id, user_id=session['user_id'], addtime=current_time) db.session.add(comment) db.session.commit() # db.session.close() movie.Movie.commentnum += 1 db.session.add(movie.Movie) db.session.commit() flash(u"添加评论成功", "ok") return redirect(url_for('home.play', id=movie.Movie.id, page=1)) print(movie.Movie.playnum) movie.Movie.playnum += 1 print(movie.Movie.playnum) db.session.add(movie.Movie) db.session.commit() return render_template("home/play.html", movie=movie, form=form, page_data=page_data)
def play(id_field=None, page=None): movie = Movie.query.join(Tag).filter( Tag.id == Movie.tag_id, Movie.id == int(id_field)).first_or_404() movie.play_num = movie.play_num + 1 if page is None: page = 1 comment_data = Comment.query.join(User).filter( User.id == Comment.user_id).filter( movie.id == Comment.movie_id).order_by( Comment.add_time.desc()).paginate(page=page, per_page=15) form = CommentForm() if 'user' in session: if form.validate_on_submit() is True: data = form.data comment = Comment( content=data['content'], movie_id=movie.id, user_id=session['user_id'], ) db.session.add(comment) db.session.commit() id_field = movie.id movie.comment_num += 1 db.session.add(movie) db.session.commit() flash('评论添加成功', 'ok') return redirect(url_for('home.play', id_field=id_field, page=1)) return render_template('home/play.html', movie=movie, form=form, comment_data=comment_data)
def video(id=None, page=None): """ 弹幕播放器 """ movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) movie.playnum = movie.playnum + 1 form = CommentForm() 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() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash("添加评论成功!", "ok") return redirect(url_for('home.video', id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template("home/video.html", movie=movie, form=form, page_data=page_data)
def detail(id=None, page=None): image = Image.query.join(Tag).filter(Tag.id == Image.tag_id, Image.id == int(id)).first_or_404() page_data = Comment.query.join(Image).join(User).filter( Image.id == image.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=3) image.playnum = image.playnum + 1 form = CommentForm() if "user" in session and form.validate_on_submit(): data = form.data comment = Comment(content=data["content"], image_id=image.id, user_id=session["user_id"]) db.session.add(comment) db.session.commit() image.commentnum = image.commentnum + 1 db.session.add(image) db.session.commit() flash("提交评论成功", 'ok') return redirect(url_for("home.detail", id=image.id, page=1)) db.session.add(image) db.session.commit() return render_template("home/detail.html", image=image, form=form, page_data=page_data)
def play(id=None, page=None): if page is None: page = 1 movie = Movie.query.get_or_404(int(id)) form = CommentForm() if 'user' in session and form.validate_on_submit(): comment = Comment(content=form.content.data, movie_id=movie.id, user_id=session['user_id']) db.session.add(comment) db.session.commit() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash('添加评论成功', 'ok') return redirect(url_for('home.play', id=movie.id, page=1)) movie.playnum = movie.playnum + 1 db.session.add(movie) db.session.commit() page_data = Comment.query.filter_by(movie_id=movie.id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=5) return render_template('home/play.html', movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): """ 详情视图 """ movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) # comment_count = Comment.query.filter().count() form = CommentForm() movie.playnum = movie.playnum + 1 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() movie.commentnum = movie.commentnum + 1 flash('添加评论成功!', 'ok') return redirect(url_for('home.play', id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template('home/play.html', movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 if 'user_id' in session: page_data = Comment.query.join(Movie).join(User).filter( Movie.id == Comment.movie_id, User.id == session['user_id']).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) else: return redirect(url_for('home.login')) movie.playnum += 1 form = CommentForm() 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() movie.commentnum += 1 db.session.add(movie) db.session.commit() flash('添加评论成功!', 'ok') return redirect(url_for("home.play", id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template("home/video.html", movie=movie, form=form, page_data=page_data)
def player(id=None, page=None): movie = Movie.query.filter(Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=5) form = CommentForm() 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() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash("Added The Review successfully !", "ok") return redirect(url_for('home.player', id=movie.id, page=1)) # 放在后面避免添加评论播放量涨2 movie.playnum = movie.playnum + 1 db.session.add(movie) db.session.commit() return render_template("home/player.html", movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): moviecol = Moviecol.query.filter_by(movie_id=int(id), user_id=int( session["user_id"])).count() movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) movie.playnums += 1 movie.commentnums += 1 form = CommentForm() 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() movie.commentnums += 1 flash("添加评论成功", 'ok') return redirect(url_for("home.play", id=movie.id, page=1)) return render_template('home/play.html', movie=movie, form=form, page_data=page_data, moviecol=moviecol)
def dplayer(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() movie.playnum += 1 form = CommentForm() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, # User.id == session['user_id'] ).order_by(Comment.addtime.desc()).paginate(page=page, per_page=10) if 'user' in session and form.validate_on_submit(): data = form.data comment = Comment(content=data['comment'], movie_id=movie.id, user_id=session['user_id']) db.session.add(comment) db.session.commit() flash('评论发布成功!', 'ok') movie.commentnum += 1 db.session.add(movie) db.session.commit() return redirect(url_for('home.dplayer', id=movie.id, page=1)) db.session.add(movie) db.session.commit() print(movie.movie_head, movie.movie_tail) return render_template('home/dplayer.html', movie=movie, form=form, page_data=page_data, user_login=user_login())
def play(id=None, page=None): form = CommentForm() movie = Movie.query.get_or_404(id) movie.playnum = movie.playnum + 1 #点开一次,播放数+1 tag = Tag.query.filter_by(id=movie.tag_id).first() #获取评论列表 if page == None: page = 1 page_data = Comment.query.join(User).filter( User.id == Comment.user_id, Comment.movie_id == id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=6) #提交评论 if 'user' in session and form.validate_on_submit(): data = form.data comment = Comment(content=data['content'], movie_id=id, user_id=session['user_id']) db.session.add(comment) db.session.commit() flash('评论成功!', 'ok') #评论成功,则该电影评论数+1 movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() return redirect(url_for('home.play', id=id, page=1)) #修改movie db.session.add(movie) db.session.commit() return render_template('home/play.html', movie=movie, tag=tag, form=form, page_data=page_data)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(User).join(Movie).filter( Movie.id == movie.id, ).order_by(Comment.add_time.desc()).paginate( page=page, per_page=10) movie.play_num += 1 form = CommentForm() if "user" in session and form.validate_on_submit(): data = form.data comment = Comment(content=data.get('content'), movie_id=movie.id, user_id=session['user_id']) db.session.add(comment) db.session.commit() movie.comment_num += 1 db.session.add(movie) db.session.commit() flash('添加评论成功!', 'ok') return redirect(url_for('home.play', id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template('home/play.html/', movie=movie, form=form, page_data=page_data)
def play(movie_id): ''' 电影播放 ''' movie = Movie.query.get(movie_id) form = CommentForm() comment_list = Comment.query.filter_by(movie_id=movie_id).order_by(Comment.addtime.desc()).limit(3) movie.playnum = movie.playnum + 1 db.session.add(movie) db.session.commit() if request.method == "GET": return render_template("home/play.html", movie=movie, form=form, comment_list=comment_list) if request.method == "POST": # 判断是否登陆 if "user" in session: if form.validate_on_submit(): comments = Comment( content=form.content.data, movie_id=movie.id, user_id=session["user_id"], ) db.session.add(comments) db.session.commit() flash("评论成功", "success") movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() return render_template("home/play.html", movie=movie, form=form, comment_list=comment_list) else: flash("用户未登录,请先行登陆", "fail") return redirect(url_for("home.login", next=request.url))
def video(id): video = Video.query.get_or_404(id) form = CommentForm() if form.validate_on_submit(): comment = Comment(content=form.content.data, video=video, author=current_user) db.session.add(comment) try: db.session.commit() flash('成功发布评论') except: flash('未知错误!请重试或联系管理员') db.session.rollback() return redirect(url_for('.video', id=video.id, page=-1)) page = request.args.get('page', 1, type=int) if page == -1: page = (video.comments.count() - 1) // current_app.config['VIDEO_COMMENTS_PER_PAGE'] + 1 pagination = video.comments.order_by(Comment.add_time.asc()).paginate( page, per_page=current_app.config['VIDEO_COMMENTS_PER_PAGE'], error_out=False) comments = pagination.items video.play() return render_template('home/video/video.html', video=video, form=form, comments=comments, pagination=pagination)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Tag.id == Movie.tag_id, Movie.id == int(id)).first_or_404() if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, # User.id == session['user_id'] User.id == Comment.user_id).order_by(Comment.addtime.desc()).paginate( page, per_page=10) movie.playnum = movie.playnum + 1 form = CommentForm() if 'user' in session and form.validate_on_submit(): data = form.data if 'script' in data['content'] or '$' in data['content'] or 'alert' in data['content'] or 'SRC' in data['content'] \ or 'IMG' in data['content'] or 'javascript' in data['content'] or 'SCRIPT' in data['content']: data['content'] = 'Hello man XSS攻击已被防止' comment = Comment(content=data['content'], movie_id=movie.id, user_id=session['user_id']) db.session.add(comment) db.session.commit() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash('添加评论成功', 'OK') return redirect(url_for('home.play', id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template('home/play.html', movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): movie = Movie.query.join(Tag).filter(Movie.tag_id == Tag.id, Movie.id == int(id)).first() #播放电影信息 if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=6) #分页内容 movie.playnum = movie.playnum + 1 #播放次数添加 form = CommentForm() if 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() movie.commentnum = movie.commentnum + 1 #评论次数添加 db.session.add(movie) db.session.commit() flash(u"评论添加成功!", "OK") return redirect(url_for('home.play', id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template("home/play.html", movie=movie, page_data=page_data, form=form)
def play(id=None, page=None): if page is None: page = 1 movie = Movie.query.join(Tag).filter( Tag.id == Movie.tag_id, Movie.id == int(id), ).first_or_404\ () page_data = Comment.query.join(Movie).join(User).filter( Movie.id == movie.id, User.id == Comment.user_id).order_by( Comment.addtime.desc()).paginate(page=page, per_page=10) movie.playnum = movie.playnum + 1 form = CommentForm() if form.validate_on_submit() and "user" in session: data = form.data comment = Comment(content=data["content"], movie_id=movie.id, user_id=session["user_id"]) movie.commentnum = movie.commentnum + 1 db.session.add(comment) db.session.commit() db.session.add(movie) db.session.commit() flash("添加评论成功", 'ok') return redirect(url_for("home.play", id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template("home/play.html", movie=movie, form=form, page_data=page_data)
def play(id=None, page=None): movie = Movie.query.join( Tag ).filter( Tag.id == Movie.tag_id, Movie.id == int(id) ).first_or_404() if page is None: page = 1 page_data = Comment.query.join( Movie ).join( User ).filter( Movie.id == movie.id, User.id == Comment.user_id ).order_by( Comment.addtime.desc() ).paginate(page=page, per_page=10) movie.playnum = movie.playnum + 1 form = CommentForm() 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() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash("添加评论成功", "ok") return redirect(url_for("home.play", id=movie.id, page=1)) db.session.add(movie) db.session.commit() comment_count = Comment.query.join( Movie ).join( User ).filter( Movie.id == movie.id, User.id == Comment.user_id ).count() movie_col = Moviecol.query.join( Movie ).join( User ).filter( Movie.id == id, User.id == session["user_id"] ).count() return render_template("home/play.html", movie=movie, form=form, page_data=page_data, comment_count=comment_count, movie_col=movie_col)
def message(): form = CommentForm() messages = db.session.query(Message).all() if form.validate_on_submit(): data = form.data message = Message(name=data['name'], content=data['content']) db.session.add(message) db.session.commit() flash("留言成功!", "ok") return redirect(url_for("home.message")) return render_template('home/message.html', form=form, messages=messages)