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) if current_user != photo.author and photo.author.receive_comment_notification: push_comment_notification(photo_id, receiver=photo.author, page=page) db.session.add(comment) db.session.commit() flash('Comment published.', 'success') flash_errors(form) return redirect(url_for('.show_photo', photo_id=photo.id))
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))