def get_template_context(self, notification): serializer = registry.get_object_serializer(notification.content_object) return { 'notification': notification, 'serializer': serializer, 'object': serializer.data.items(), 'ui_url': registry.get_ui_url(notification.content_object), }
def get_template_context(self, notification): serializer = registry.get_object_serializer( notification.content_object) return { 'notification': notification, 'serializer': serializer, 'object': serializer.data.items(), 'ui_url': registry.get_ui_url(notification.content_object), }
def send_notification(self, notification): ui_url = registry.get_ui_url(notification.content_object) notification_text = 'Event {} triggered on {}'.format(notification.event.tag, notification.content_object.title) fields = [] health = getattr(notification.content_object, 'health') activity = getattr(notification.content_object, 'activity') if health is not None: fields.append({ 'title': 'Health', 'value': health, 'short': True, }) if activity is not None: fields.append({ 'title': 'Activity', 'value': activity or '-', 'short': True, }) chat_kwargs = { 'channel': self.get_option(notification, 'channel'), 'as_user': self.post_as_user, 'attachments': [ { 'fallback': notification_text, 'author_name': 'stackd.io', 'author_link': settings.STACKDIO_CONFIG.server_url, 'title': six.text_type(notification.content_object.title), 'title_link': ui_url, 'text': notification_text, 'fields': fields, 'ts': int(notification.created.strftime('%s')), } ] } time.time() result = self.slackclient.api_call('chat.postMessage', **chat_kwargs) return result['ok']