def comment(id): comment = Comment.query.get_or_404(id) authorid = comment.author_id postid = comment.post_id post = Post.query.get_or_404(postid) user = User.query.get_or_404(authorid) page = request.args.get('page', 1, type=int) form = ReplyForm() if form.validate_on_submit(): user_url = url_for('user', username=user.username, _external=True) reply = Comment(body_html= '<a href="' + user_url + '">@' + user.username + '</a> ' + form.body.data, timestamp=datetime.utcnow(), post=post, author=current_user._get_current_object()) db.session.add(reply) db.session.flush() r = comment.reply(reply) db.session.add(r) db.session.commit() flash('Your comment has been published.') commenturl = url_for('post', id=post.id, page=page, _external=True) if user.email: reply_notification(user, g.user, commenturl) return redirect(url_for('post', id=post.id, page=page))
def reply(): form = ReplyForm() if form.validate_on_submit(): u = User.query.filter_by(id = g.user.id).first() t = Topic.query.filter_by(id = form.topic_id.data).first() reply = Reply(thread=t, author=u, content=form.content.data) db.session.add(reply) db.session.commit() flash("回复成功") return redirect(request.args.get("next") or url_for("index")) form.topic_id.data = request.args.get('topic_id', '') return render_template('reply.html', form = form, title = '新建')
def reply(comment_id): comment = Comment.query.get_or_404(comment_id) form = ReplyForm() reply_id = request.args.get('reply_id') is_reply = bool(request.args.get('is_reply')) if form.validate_on_submit(): if not is_reply: pids = "" else: result = Reply.query.with_entities( Reply.pids).filter_by(id=reply_id).first() pids = str(result[0]) + ':' + str(reply_id) reply = Reply(body=form.body.data, author=current_user._get_current_object(), comment=comment, pids=pids) db.session.add(reply) return redirect(url_for('.post', id=comment.post_id)) return render_template('post.html', form=form)
def show_comment(comment_id): form = ReplyForm() reply_page = request.args.get('c_page', 1) deleted = request.args.get('deleted') post_id = request.args.get('post_id') requested_comment, replies, parent_post = get_comment_elements( comment_id, deleted, post_id) if form.validate_on_submit(): return add_reply(requested_comment, form.reply.data, reply_page) return handle_page(endpoint='post.html', count_arg='c_count', page_id=reply_page, page_arg='current_c', items_lst=replies, items_arg='replies', original_comment=requested_comment, post=parent_post, comments=[requested_comment], form=form, deleted=str(deleted), post_id=post_id, comment=True)