コード例 #1
0
ファイル: serializers.py プロジェクト: butilities/aleph
 def _collect(self, obj):
     self.queue(Role, obj.get("actor_id"))
     event = Events.get(obj.get("event"))
     if event is not None:
         for name, clazz in event.params.items():
             key = obj.get("params", {}).get(name)
             self.queue(clazz, key, Entity.THING)
コード例 #2
0
ファイル: serializers.py プロジェクト: modulexcite/aleph
 def _serialize(self, obj):
     event = Events.get(obj.get('event'))
     params = {
         'actor': self.resolve(Role, obj.get('actor_id'), RoleSerializer)
     }
     for name, clazz in event.params.items():
         key = obj.get('params', {}).get(name)
         serializer = self.SERIALIZERS.get(clazz)
         params[name] = self.resolve(clazz, key, serializer)
     obj['params'] = params
     obj['event'] = event.to_dict()
     return obj
コード例 #3
0
ファイル: serializers.py プロジェクト: mudsill/aleph
 def _serialize(self, obj):
     event = Events.get(obj.get("event"))
     if event is None:
         return None
     params = {"actor": self.resolve(Role, obj.get("actor_id"), RoleSerializer)}
     for name, clazz in event.params.items():
         key = obj.get("params", {}).get(name)
         serializer = self.SERIALIZERS.get(clazz)
         params[name] = self.resolve(clazz, key, serializer)
     obj["params"] = params
     obj["event"] = event.to_dict()
     return obj
コード例 #4
0
ファイル: notifications.py プロジェクト: butilities/aleph
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 == EntitySet:
            title = data.label
            link = entityset_url(data.id)
        elif clazz == Export:
            title = data.get("label")
            link = archive_url(
                data.get("content_hash"),
                file_name=data.get("file_name"),
                mime_type=data.get("file_name"),
            )
            link = url_for("exports_api.download", export_id=data.get("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}
コード例 #5
0
ファイル: notifications.py プロジェクト: x0rzkov/aleph
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}
コード例 #6
0
ファイル: serializers.py プロジェクト: modulexcite/aleph
 def _collect(self, obj):
     self.queue(Role, obj.get('actor_id'))
     event = Events.get(obj.get('event'))
     for name, clazz in event.params.items():
         key = obj.get('params', {}).get(name)
         self.queue(clazz, key, Entity.THING)
コード例 #7
0
 def update(self, result, key):
     event = Events.get(key)
     result["label"] = key if event is None else event.title