Esempio n. 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)
Esempio n. 2
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)
Esempio n. 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)
Esempio n. 4
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)