def process_send(
self,
message_type,
recipients,
events,
request,
user,
source,
sources=None,
related=None,
**kwargs,
):
if sources is None:
sources = []
try:
# If this was a batch action we want to pull out the submission
source = sources[0]
except IndexError:
pass
kwargs = {
"request": request,
"user": user,
"source": source,
"sources": sources,
"related": related,
**kwargs,
}
kwargs.update(self.get_neat_related(message_type, related))
kwargs.update(self.extra_kwargs(message_type, **kwargs))
for recipient in recipients:
# Allow for customization of message based on recipient string (will vary based on adapter)
message_kwargs = {**kwargs, "recipient": recipient}
message = self.message(message_type, **message_kwargs)
if not message:
continue
message_logs = self.create_logs(message, recipient, *events)
if settings.SEND_MESSAGES or self.always_send:
status = self.send_message(
message, recipient=recipient, logs=message_logs, **kwargs
)
else:
status = "Message not sent as SEND_MESSAGES==FALSE"
message_logs.update_status(status)
if not settings.SEND_MESSAGES:
if recipient:
debug_message = "{} [to: {}]: {}".format(
self.adapter_type, recipient, message
)
else:
debug_message = "{}: {}".format(self.adapter_type, message)
messages.add_message(request, messages.DEBUG, debug_message)