models.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:django-email-queue 作者: wooyek 项目源码 文件源码
def _create(cls, email_message, commit=True):
        """A factory method creates model from a base django EmailMultiAlternatives instance."""
        assert email_message.recipients()

        instance = cls()
        instance.encoding = email_message.encoding or settings.DEFAULT_CHARSET
        instance.from_email = email_message.from_email
        instance.to = EMAIL_ADDRESS_SEPARATOR.join(email_message.to)
        instance.cc = EMAIL_ADDRESS_SEPARATOR.join(email_message.cc)
        instance.bcc = EMAIL_ADDRESS_SEPARATOR.join(email_message.bcc)
        instance.reply_to = EMAIL_ADDRESS_SEPARATOR.join(email_message.reply_to)
        instance.subject = email_message.subject
        instance.body_text = email_message.body

        for content, mime_type in email_message.alternatives:
            if mime_type != HTML_MIME_TYPE:
                msg = "Only '{}' mime type is supported, can not send a message with {} alternative"
                msg.format(HTML_MIME_TYPE, mime_type)
                raise NotImplementedError(msg)
            instance.body_html = content

        if commit:
            instance.save()

        return instance
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号