def send(self, raise_exception=False, user=None):
"""
Handles the preparing the notification for sending. Called to trigger the send from code.
If raise_exception is True, it will raise any exceptions rather than simply logging them.
returns boolean whether or not the notification was sent successfully
"""
context = self.get_context_data()
recipients = self.get_recipients()
if 'text' in self.render_types:
text_content = self.render('text', context)
else:
text_content = None
if 'html' in self.render_types:
html_content = self.render('html', context)
else:
html_content = None
sent_from = self.get_sent_from()
subject = self.get_subject()
extra_data = self.get_extra_data()
sent_notification = SentNotification(
recipients=','.join(recipients),
text_content=text_content,
html_content=html_content,
sent_from=sent_from,
subject=subject,
extra_data=json.dumps(extra_data) if extra_data else None,
notification_class=self.get_class_path(),
attachments=self._get_encoded_attachments(),
user=user,
)
return self.resend(sent_notification, raise_exception=raise_exception)
评论列表
文章目录