예제 #1
0
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
예제 #2
0
 def serialize(self, dumps=False):
     data = {
         'uuid': self.uuid.hex,
         'timestamp': to_timestamp(self.datetime),
         'type': self.event_type,
         'data': self.data,
     }
     return dumps_htmlsafe(data) if dumps else data
예제 #3
0
 def extract(self, value):
     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)
예제 #4
0
 def extract(self, value):
     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)
예제 #5
0
 def serialize(self, dumps=False):
     data = {
         'uuid': self.uuid.hex,
         'timestamp': to_timestamp(self.datetime),
         'type': self.event_type,
         'data': self.data,
     }
     return dumps_htmlsafe(data) if dumps else data
예제 #6
0
    def serialize_event_to_context(cls, event):
        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
예제 #7
0
파일: event.py 프로젝트: sher-ali/polyaxon
 def serialize(self, dumps=False, include_actor_name=True):
     _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,
     }
     return dumps_htmlsafe(data) if dumps else data
예제 #8
0
def build_attachment(event):
    logo_url = ''  # TODO: add logo url

    text = build_attachment_text(event) or ''

    fields = []  # Use build_field

    event_object_context = event_context.get_event_object_context(
        event_content_object=event.instance, event_type=event.event_type)

    ts = event.created_at

    if event:
        event_ts = event.datetime
        ts = max(ts, event_ts)

    payload = {
        'fallback':
        u'[{}] {}',
        'title':
        build_attachment_title(event),
        'title_link':
        add_notification_referrer_param(event_object_context.url, 'slack'),
        'text':
        text,
        'fields':
        fields,
        'mrkdwn_in': ['text'],
        'footer_icon':
        logo_url,
        'footer':
        get_footer(),
        'color':
        EventColor.get_for_event(event_content_object=event.instance,
                                 event_type=event.event_type),
    }

    if ts:
        payload['ts'] = to_timestamp(ts)