def new_comment(photo_id): photo = Photo.query.get_or_404(photo_id) page = request.args.get('page', 1, type=int) form = CommentForm() if form.validate_on_submit(): body = form.body.data author = current_user._get_current_object() comment = Comment(body=body, author=author, photo=photo) replied_id = request.args.get('reply') if replied_id: comment.replied = Comment.query.get_or_404(replied_id) if comment.replied.author.receive_comment_notification: push_comment_notification(photo_id=photo.id, receiver=comment.replied.author) db.session.add(comment) db.session.commit() flash('Comment published.', 'success') if current_user != photo.author and photo.author.receive_comment_notification: push_comment_notification(photo_id, receiver=photo.author, page=page) flash_errors(form) return redirect(url_for('.show_photo', photo_id=photo_id, page=page))
def new_comment(photo_id): """ 新的评论 :param photo_id: 图片id """ logger.info('url = ' + str(request.url)) photo = Photo.query.get_or_404(photo_id) page = request.args.get("page", 1, type=int) form = CommentForm() if form.validate_on_submit(): body = form.body.data author = current_user._get_current_object() comment = Comment(body=body, author=author, photo=photo) logger.info('用户:{}对图片:{}发表了评论:{}'.format(current_user.username, photo_id, body)) # 被回复的用户 replied_id = request.args.get("reply") if replied_id: comment.replied = Comment.query.get_or_404(replied_id) if comment.replied.author.receive_comment_notification: push_comment_notification( photo_id=photo.id, receiver=comment.replied.author ) db.session.add(comment) db.session.commit() flash("评论成功!", "success") if current_user != photo.author and photo.author.receive_comment_notification: push_comment_notification(photo_id, receiver=photo.author, page=page) flash_errors(form) return redirect(url_for(".show_photo", photo_id=photo_id, page=page))
def show_photo(photo_id): """ 显示图片详细信息 :param photo_id: 图片id """ logger.info('url = ' + str(request.url)) photo = Photo.query.get_or_404(photo_id) page = request.args.get("page", 1, type=int) per_page = current_app.config["ALBUMY_COMMENT_PER_PAGE"] # 获取该图片下的所有评论 pagination = ( Comment.query.with_parent(photo) .order_by(Comment.timestamp.asc()) .paginate(page, per_page) ) comments = pagination.items comment_form = CommentForm() # 描述 description_form = DescriptionForm() # 标签 tag_form = TagForm() description_form.description.data = photo.description return render_template( "main/photo.html", photo=photo, comment_form=comment_form, description_form=description_form, tag_form=tag_form, pagination=pagination, comments=comments, )
def show_photo(photo_id): photo = Photo.query.get_or_404(photo_id) page = request.args.get('page', 1, type=int) per_page = current_app.config['ALBUMY_COMMENT_PER_PAGE'] pagination = Comment.query.with_parent(photo).order_by(Comment.timestamp.asc()).paginate(page, per_page) comments = pagination.items comment_form = CommentForm() description_form = DescriptionForm() tag_form = TagForm() description_form.description.data = photo.description if current_user.role.name != 'Doctor': doctors_leave_comment = [] doctor_ids_leave_comment = [] for comment in photo.comments: print(comment.author) if not comment.author in doctors_leave_comment: if comment.author.role.name == 'Doctor': doctors_leave_comment.append(comment.author) doctor_ids_leave_comment.append(comment.author.id) doctors_not_leave_comment = User.query.join(Role).filter(Role.name == 'Doctor').filter( ~User.id.in_(doctor_ids_leave_comment)).all() return render_template('main/photo.html', photo=photo, comment_form=comment_form, description_form=description_form, tag_form=tag_form, pagination=pagination, comments=comments, doctors_leave_comment=doctors_leave_comment, doctors_not_leave_comment=doctors_not_leave_comment) else: invite = photo.invites.filter(Invite.user_id == current_user.id, Invite.status == False).first() return render_template('main/photo.html', photo=photo, comment_form=comment_form, description_form=description_form, tag_form=tag_form, pagination=pagination, comments=comments, invite=invite)
def show_photo(photo_id): photo = Photo.query.get_or_404(photo_id) page = request.args.get('page', 1, type=int) per_page = current_app.config['ALBUMY_COMMENT_PER_PAGE'] pagination = Comment.query.with_parent(photo).order_by(Comment.timestamp.asc()).paginate(page, per_page) comments = pagination.items comment_form = CommentForm() description_form = DescriptionForm() tag_form = TagForm() description_form.description.data = photo.description return render_template('main/photo.html', photo=photo, comment_form=comment_form, description_form=description_form, tag_form=tag_form, pagination=pagination, comments=comments)