def render_notification(stub, notification): """Generate a text version of the notification, suitable for use in an email or text message.""" from aleph.logic import resolver for name, clazz, value in notification.iterparams(): resolver.queue(stub, clazz, value) resolver.resolve(stub) plain = str(notification.event.template) html = str(notification.event.template) for name, clazz, value in notification.iterparams(): data = resolver.get(stub, clazz, value) if data is None: return link, title = None, None if clazz == Role: title = data.get('label') elif clazz == Alert: title = data.get('query') elif clazz == Collection: title = data.get('label') link = collection_url(value) elif clazz == Entity: title = data.get('name') link = entity_url(value) template = '{{%s}}' % name html = html.replace(template, html_link(title, link)) plain = plain.replace(template, "'%s'" % title) if name == notification.event.link_to: plain = '%s (%s)' % (plain, link) return {'plain': plain, 'html': html}
def render_notification(notification): """ Generate a text version of the notification, suitable for use in an email or text message. """ message = str(notification.event.template) for name, clazz, value in notification.iterparams(): template = '{{%s}}' % name text = html_link(*resolve_id(value, clazz)) message = message.replace(template, text) return message
def render_notification(stub, notification): """Generate a text version of the notification, suitable for use in an email or text message.""" from aleph.logic import resolver notification = unpack_result(notification) event = Events.get(notification.get('event')) if event is None: return for name, clazz, value in _iter_params(notification, event): resolver.queue(stub, clazz, value) resolver.resolve(stub) plain = str(event.template) html = str(event.template) for name, clazz, value in _iter_params(notification, event): data = resolver.get(stub, clazz, value) if data is None: return link, title = None, None if clazz == Role: title = data.get('label') elif clazz == Alert: title = data.get('query') elif clazz == Collection: title = data.get('label') link = collection_url(value) elif clazz == Entity: proxy = model.get_proxy(data) title = proxy.caption link = entity_url(value) elif clazz == Diagram: title = data.label link = diagram_url(data.id) template = '{{%s}}' % name html = html.replace(template, html_link(title, link)) plain = plain.replace(template, "'%s'" % title) if name == event.link_to: plain = '%s (%s)' % (plain, link) return {'plain': plain, 'html': html}