예제 #1
0
    def add_comment(self, author, diary_id, email, content):
        diary = Diary.objects(pk=diary_id)
        diary_title = diary.first().title
        comment_em = CommentEm(
            author=author,
            content=content,
            email=email
        )
        diary.update_one(push__comments=comment_em)

        comment = Comment(content=content)
        comment.diary = diary.first()
        comment.email = email
        comment.author = author
        comment.save(validate=False)

        try:
            send_email_task(Config.EMAIL,
                            Config.MAIN_TITLE + u'收到了新的评论, 请查收',
                            content, diary_id, author, diary_title)

            response = make_response(json.dumps({'success': 'true'}))
            response.set_cookie('guest_name', author)
            response.set_cookie('guest_email', email)

            return response
        except Exception as e:
            return str(e)
예제 #2
0
    def reply_comment(self, author, diary_id, email, content):
        diary = Diary.objects(pk=diary_id)
        diary_title = diary.first().title
        comment_em = CommentEm(author=u"博主回复", content=content)
        diary.update_one(push__comments=comment_em)

        """ Save in Comment model for admin manage"""
        comment = Comment(content=content)
        comment.diary = diary.first()
        comment.author = UserDispatcher().get_profile().name
        comment.save(validate=False)

        try:
            send_email_task(
                email,
                u"您评论的文章《"
                + diary_title
                + u"》收到了来自\
                            博主的回复, 请查收",
                content,
                diary_id,
                author,
                diary_title,
            )

            return json.dumps({"success": "true"})
        except Exception as e:
            return json.dumps({"success": "false", "reason": str(e)})
예제 #3
0
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_email_task(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)
예제 #4
0
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_email_task(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)})
예제 #5
0
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_email_task(
                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)})
예제 #6
0
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_email_task(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)
예제 #7
0
    def reply_comment(self, author, diary_id, email, content):
        diary = Diary.objects(pk=diary_id)
        diary_title = diary.first().title
        comment_em = CommentEm(
            author=u'博主回复',
            content=content,
        )
        diary.update_one(push__comments=comment_em)
        ''' Save in Comment model for admin manage'''
        comment = Comment(content=content)
        comment.diary = diary.first()
        comment.author = UserDispatcher().get_profile().name
        comment.save(validate=False)

        try:
            send_email_task(
                email, u'您评论的文章《' + diary_title + u'》收到了来自\
                            博主的回复, 请查收', content, diary_id, author,
                diary_title)

            return json.dumps({'success': 'true'})
        except Exception as e:
            return json.dumps({'success': 'false', 'reason': str(e)})
예제 #8
0
    def add_comment(self, author, diary_id, email, content):
        diary = Diary.objects(pk=diary_id)
        diary_title = diary.first().title
        comment_em = CommentEm(author=author, content=content, email=email)
        diary.update_one(push__comments=comment_em)

        comment = Comment(content=content)
        comment.diary = diary.first()
        comment.email = email
        comment.author = author
        comment.save(validate=False)

        try:
            send_email_task(Config.EMAIL, Config.MAIN_TITLE + u'收到了新的评论, 请查收',
                            content, diary_id, author, diary_title)

            response = make_response(json.dumps({'success': 'true'}))
            response.set_cookie('guest_name', author)
            response.set_cookie('guest_email', email)

            return response
        except Exception as e:
            return str(e)
예제 #9
0
    def reply_comment(self, author, diary_id, email, content):
        diary = Diary.objects(pk=diary_id)
        diary_title = diary.first().title
        comment_em = CommentEm(
            author=u'博主回复',
            content=content,
        )
        diary.update_one(push__comments=comment_em)

        ''' Save in Comment model for admin manage'''
        comment = Comment(content=content)
        comment.diary = diary.first()
        comment.author = UserDispatcher().get_profile().name
        comment.save(validate=False)

        try:
            send_email_task(email, u'您评论的文章《' + diary_title + u'》收到了来自\
                            博主的回复, 请查收', content, diary_id, author,
                            diary_title)

            return json.dumps({'success': 'true'})
        except Exception as e:
            return json.dumps({'success': 'false', 'reason': str(e)})