models.py 文件源码

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

项目:Bitpoll 作者: fsinfuhh 项目源码 文件源码
def send(self, request, vote: Vote):
        old_lang = translation.get_language()
        translation.activate(self.user.language)
        link = reverse('poll', args=(self.poll.url,))
        if vote.anonymous:
            username = _("Annonymus")
        elif vote.user:
            username = vote.user.username
        else:
            username = vote.name
        email_content = render_to_string('poll/mail_watch.txt', {
            'receiver': self.user.username,
            'user': username if self.poll.show_results == "complete" else _("by an user"),
            'poll': self.poll.title,
            'link': link,
            'hide_participants': self.poll.hide_participants  # TODO: simplify merge with usernameshadowing above
        })
        try:
            send_mail(_("New votes for {}".format(self.poll.title)), email_content, None,
                      [self.user.email])
        except SMTPRecipientsRefused:
            translation.activate(old_lang)
            messages.error(
                request, _("The mail server had an error sending the notification to {}".format(
                    self.user.username))
            )
        translation.activate(old_lang)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号