Handle both event instanciation from object and from serialized events
@@ -9,12 +9,16 @@ class EventService(Service):
def can_handle(self, event_type):
return isinstance(event_type, str) and self.event_manager.knows(event_type)
- def get_event(self, event_type, instance, **kwargs):
+ def get_event(self, event_type, event_data=None, instance=None, **kwargs):
+ if instance or not event_data:
return self.event_manager.get(
event_type,
).from_instance(instance, **kwargs)
+ return self.event_manager.get(
+ event_type,
+ ).from_event_data(event_data=event_data, **kwargs)
- def record(self, event_type, instance=None, **kwargs):
+ def record(self, event_type, event_data=None, instance=None, **kwargs):
""" Validate and record an event.
>>> record('event.action', object_instance)
@@ -24,8 +28,12 @@ class EventService(Service):
if not self.can_handle(event_type=event_type):
return
- event = self.get_event(event_type=event_type, instance=instance, **kwargs)
+ event = self.get_event(event_type=event_type,
+ event_data=event_data,
+ instance=instance,
+ **kwargs)
self.record_event(event)
+ return event
def record_event(self, event):
""" Record an event.
