def send(
self, message_type, request, user, related, source=None, sources=None, **kwargs
):
from .models import Event
if sources is None:
sources = []
if source:
event = Event.objects.create(type=message_type.name, by=user, source=source)
for adapter in self.adapters:
adapter.process(
message_type,
event,
request=request,
user=user,
source=source,
related=related,
**kwargs,
)
elif sources:
events = Event.objects.bulk_create(
Event(type=message_type.name, by=user, source=source)
for source in sources
)
for adapter in self.adapters:
adapter.process_batch(
message_type,
events,
request=request,
user=user,
sources=sources,
related=related,
**kwargs,
)