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)
评论列表
文章目录