def serialize_event_to_context(event): event_context = get_event_context(event) logo_url = '' # TODO: add logo url fields = [] # Use build_field url = add_notification_referrer_param(event_context.object_context.url, provider='slack', is_absolute=False) payload = { 'fallback': event_context.subject_action, 'title': event_context.subject_action, 'title_link': url, 'text': get_readable_event(event_context), 'fields': fields, 'mrkdwn_in': ['text'], 'footer_icon': logo_url, 'footer': 'Polyaxon', 'color': EventColor.get_for_event(event_content_object=event.instance, event_type=event.event_type), 'ts': to_timestamp(event.datetime) } return payload
def extract(self, value: Any) -> Any: if value is None: return value if self.is_datetime: return to_timestamp(value) if self.is_uuid and not isinstance(value, str): return value.hex return self.attr_type(value)
def serialize_event_to_context(cls, event: Event) -> Dict: event_context = get_event_context(event) context = { 'subject': event_context.subject_action, 'body': get_readable_event(event_context), 'datetime': to_timestamp(event_context.datetime) } return context
def serialize(self, dumps=False, include_actor_name=True, include_instance_info=False): _data = self.data if not include_actor_name and self.actor and self.actor_name in _data: _data = copy.deepcopy(self.data) _data.pop(self.actor_name) data = { 'uuid': self.uuid.hex, 'timestamp': to_timestamp(self.datetime), 'type': self.event_type, 'data': _data, } if include_instance_info: data['instance_id'] = self.instance_id data['instance_contenttype'] = self.instance_contenttype return dumps_htmlsafe(data) if dumps else data