Add pulling.
This commit is contained in:
parent
b94c29bad0
commit
620e430f4b
|
@ -34,9 +34,10 @@ def index():
|
|||
return render_template(
|
||||
'node_rendered.html',
|
||||
node=n,
|
||||
backlinks=[x.wikilink for x in db.nodes_by_outlink(node)],
|
||||
backlinks=n.back_links(),
|
||||
pushlinks=n.push_links() if n else [],
|
||||
pull_nodes=n.pull_nodes() if n else [],
|
||||
pulling_nodes=n.pulling_nodes() if n else [],
|
||||
forwardlinks=n.forward_links() if n else [],
|
||||
)
|
||||
|
||||
|
@ -123,11 +124,12 @@ def node(node):
|
|||
return render_template(
|
||||
'node_rendered.html',
|
||||
node=n,
|
||||
backlinks=[x.wikilink for x in db.nodes_by_outlink(node)],
|
||||
backlinks=n.back_links(),
|
||||
pushlinks=n.push_links() if n else [],
|
||||
pull_nodes=n.pull_nodes() if n else [],
|
||||
forwardlinks=n.forward_links() if n else [],
|
||||
search=search_subnodes,
|
||||
pulling_nodes=n.pulling_nodes(),
|
||||
query=n.wikilink.replace('-', '%20')
|
||||
)
|
||||
|
||||
|
|
19
app/db.py
19
app/db.py
|
@ -118,6 +118,10 @@ class Node:
|
|||
links.extend(subnode.go())
|
||||
return links
|
||||
|
||||
# The following section is particularly confusing.
|
||||
# Some functions return wikilinks, some return full blown nodes.
|
||||
# We probably want to converge on the latter.
|
||||
# TODO: fix.
|
||||
def forward_links(self):
|
||||
links = []
|
||||
for subnode in self.subnodes:
|
||||
|
@ -127,17 +131,32 @@ class Node:
|
|||
# Pattern: (subject).action_object.
|
||||
# Could be modeled with RDF?
|
||||
def pull_nodes(self):
|
||||
# the nodes *being pulled* by this node.
|
||||
nodes = []
|
||||
for subnode in self.subnodes:
|
||||
nodes.extend(subnode.pull_nodes())
|
||||
return sorted(set(nodes), key=lambda x: x.uri)
|
||||
|
||||
def pulling_nodes(self):
|
||||
# the nodes pulling *this* node.
|
||||
# compare with: pull_nodes.
|
||||
nodes = []
|
||||
for wikilink in self.back_links():
|
||||
n = G.node(wikilink)
|
||||
if self.wikilink in [n.wikilink for n in n.pull_nodes()]:
|
||||
nodes.append(n)
|
||||
return nodes
|
||||
|
||||
def push_links(self):
|
||||
links = []
|
||||
for subnode in self.subnodes:
|
||||
links.extend(subnode.push_links())
|
||||
return sorted(set(links))
|
||||
|
||||
def back_links(self):
|
||||
return sorted([x.wikilink for x in nodes_by_outlink(self.wikilink)])
|
||||
|
||||
|
||||
|
||||
class Subnode:
|
||||
"""A subnode is a note or media resource volunteered by a user of the Agora.
|
||||
|
|
|
@ -34,11 +34,17 @@
|
|||
-->
|
||||
|
||||
<div class="pulllinks">
|
||||
<span class="pulllinks-header">↑ pulled</span><br />
|
||||
<span class="pulllinks-header">↑ pulled by this node</span><br />
|
||||
{% for node in pull_nodes %}
|
||||
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
||||
{% endfor %}
|
||||
<br />
|
||||
<span class="pulllinks-header">↓ pulling this node</span><br />
|
||||
{% for node in pulling_nodes %}
|
||||
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
||||
{% endfor %}
|
||||
<br />
|
||||
|
||||
</div>
|
||||
|
||||
<div class="forwardlinks">
|
||||
|
|
Loading…
Reference in New Issue