# Path: djangoblog/utils.py
# @cache_decorator()
# def get_current_site():
#     site = Site.objects.get_current()
#     return site
# 
# Path: djangoblog/utils.py
# def send_email(emailto, title, content):
#     from djangoblog.blog_signals import send_email_signal
#     send_email_signal.send(
#         send_email.__class__,
#         emailto=emailto,
#         title=title,
#         content=content)


import logging
from djangoblog.utils import get_current_site
from djangoblog.utils import send_email

logger = logging.getLogger(__name__)


def send_comment_email(comment):
    site = get_current_site().domain
    subject = '感谢您发表的评论'
    article_url = "https://{site}{path}".format(
        site=site, path=comment.article.get_absolute_url())
    html_content = """
                   <p>非常感谢您在本站发表评论</p>
                   您可以访问
                   <a href="%s" rel="bookmark">%s</a>
                   来查看您的评论，
                   再次感谢您！
                   <br />
                   如果上面链接无法打开，请将此链接复制至浏览器。
                   %s
                   """ % (article_url, comment.article.title, article_url)
    tomail = comment.author.email
    send_email([tomail], subject, html_content)
    try:
        if comment.parent_comment:
            html_content = """
                    您在 <a href="%s" rel="bookmark">%s</a> 的评论 <br/> %s <br/> 收到回复啦.快去看看吧
                    <br/>
                    如果上面链接无法打开，请将此链接复制至浏览器。
                    %s
                    """ % (article_url, comment.article.title, comment.parent_comment.body, article_url)
            tomail = comment.parent_comment.author.email

# Path: djangoblog/utils.py
# @cache_decorator()
# def get_current_site():
#     site = Site.objects.get_current()
#     return site
# 
# Path: djangoblog/utils.py
# def send_email(emailto, title, content):
#     from djangoblog.blog_signals import send_email_signal
#     send_email_signal.send(
#         send_email.__class__,
#         emailto=emailto,
#         title=title,
#         content=content)


# Path: comments/utils.py
import logging
from djangoblog.utils import get_current_site
from djangoblog.utils import send_email


logger = logging.getLogger(__name__)


def send_comment_email(comment):
    site = get_current_site().domain
    subject = '感谢您发表的评论'
    article_url = "https://{site}{path}".format(
        site=site, path=comment.article.get_absolute_url())
    html_content = """
                   <p>非常感谢您在本站发表评论</p>
                   您可以访问
                   <a href="%s" rel="bookmark">%s</a>
                   来查看您的评论，
                   再次感谢您！
                   <br />
                   如果上面链接无法打开，请将此链接复制至浏览器。
                   %s
                   """ % (article_url, comment.article.title, article_url)
    tomail = comment.author.email
    send_email([tomail], subject, html_content)
    try:
        if comment.parent_comment:
            html_content = """
                    您在 <a href="%s" rel="bookmark">%s</a> 的评论 <br/> %s <br/> 收到回复啦.快去看看吧
                    <br/>
                    如果上面链接无法打开，请将此链接复制至浏览器。
                    %s
                    """ % (article_url, comment.article.title, comment.parent_comment.body, article_url)
            tomail = comment.parent_comment.author.email

            send_email([tomail], subject, html_content)