def comment_reply(): """Comment Reply Action. Used for reply guests comment and send notification email. Methods: POST Args: author: guest_name did: diaryObjectID title: diary_title email: guest_email content: reply content Returns: status: {success: true/false , reason: Exception} """ if request.method == 'POST': author = request.form['author'] did = request.form['did'] title = request.form['title'] email = request.form['email'] content = request.form['content'] post = Diary.objects(pk=did) commentEm = CommentEm( author = u'博主回复', content = content, ) post.update_one(push__comments=commentEm) ''' Save in Comment Model for admin manage''' comment = Comment(content=content) comment.diary = post[0] comment.author = current_user.name comment.save(validate=False) try: send_reply_mail(email, u'您评论的文章《' + title + u'》收到了来自\ 博主的回复, 请查收', content, did, author, title) return json.dumps({'success': 'true'}) except Exception as e: return json.dumps({'success': 'false', 'reason': str(e)})
def comment_add(): """ Comment Add AJAX Post Action. designed for ajax post and send reply email for admin Args: username: guest_name did: diary ObjectedId email: guest_email content: comment content Return: email_status: success """ if request.method == 'POST': name = request.form['username'] did = request.form['did'] email = request.form['email'] content = request.form['comment'] post = Diary.objects(pk=did) diary_title = post[0].title commentEm = CommentEm( author = name, content = content, email = email ) post.update_one(push__comments=commentEm) comment = Comment(content=content) comment.diary = post[0] comment.email = email comment.author = name comment.save(validate=False) try: send_reply_mail(Config.EMAIL, Config.MAIN_TITLE + u'收到了新的评论, 请查收', content, did, name, diary_title) response = make_response(json.dumps({'success': 'true'})) response.set_cookie('guest_name', name) response.set_cookie('guest_email', email) return response except Exception as e: return str(e)