Exemplo n.º 1
0
    def on_revision_by_id(self, request, rid):
        result = super().on_revision_by_id(request, rid)

        result.refs = refs = Record()
        refs.branch = self.build_url(request,
                                     "branches.branch_by_id",
                                     bid=result.rid.branch)

        refs.ancestors = Record()
        for number, rid in enumerate(result.ancestors):
            refs.ancestors[number] = self.build_url(request,
                                                    "revisions.revision_by_id",
                                                    rid=rid)

        refs.nodes = Record()
        for number, node_ref in enumerate(result.nodes):
            refs.nodes[number] = self.build_url(request,
                                                "nodes.by_uid",
                                                uid=NodeId(
                                                    node_ref, result.rid))

        refs.nodes_refs = Record()
        for number, (ref, rid) in enumerate(result.nodes_refs.items()):
            refs.nodes_refs[number] = self.build_url(request,
                                                     "nodes.by_uid",
                                                     uid=NodeId(
                                                         ref, result.rid))

        return result
Exemplo n.º 2
0
    def on_by_uid(self, request, uid):
        uid = NodeId.from_string(uid)
        node = self.runtime.get_node(uid)
        if node is None:
            raise NotFound()

        result = Record()
        result["="] = type(node).__name__
        result.ref = node.ref
        result.data = node.content

        return result
Exemplo n.º 3
0
    def on_by_uid(self, request, uid):
        result = super().on_by_uid(request, uid)

        uid = NodeId.from_string(uid)
        revision = self.runtime.get_revision(uid.revision)

        result.refs = refs = Record()
        for name, value in result.data.items():
            inspected = self.inspect(request, revision, value)
            if inspected is not None:
                refs[name] = inspected

        return result
Exemplo n.º 4
0
 def inspect(self, request, revision, value):
     if isinstance(value, NodeRef):
         uid = NodeId(value, revision.search(value).id)
         return self.build_url(request, "nodes.by_uid", uid=uid)
     elif isinstance(value, tuple):
         result = Record()
         for number, subvalue in enumerate(value):
             subinspect = self.inspect(request, revision, subvalue)
             if subinspect is not None:
                 result[number] = subinspect
         if result: return result
     elif isinstance(value, ReadOnlyDict):
         result = Record()
         for name, subvalue in value.items():
             subinspect = self.inspect(request, revision, subvalue)
             if subinspect is not None:
                 result[name] = subinspect
         if result: return result