Add pulling.
This commit is contained in:
parent
b94c29bad0
commit
620e430f4b
3 changed files with 30 additions and 3 deletions
|
@ -34,9 +34,10 @@ def index():
|
||||||
return render_template(
|
return render_template(
|
||||||
'node_rendered.html',
|
'node_rendered.html',
|
||||||
node=n,
|
node=n,
|
||||||
backlinks=[x.wikilink for x in db.nodes_by_outlink(node)],
|
backlinks=n.back_links(),
|
||||||
pushlinks=n.push_links() if n else [],
|
pushlinks=n.push_links() if n else [],
|
||||||
pull_nodes=n.pull_nodes() 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 [],
|
forwardlinks=n.forward_links() if n else [],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -123,11 +124,12 @@ def node(node):
|
||||||
return render_template(
|
return render_template(
|
||||||
'node_rendered.html',
|
'node_rendered.html',
|
||||||
node=n,
|
node=n,
|
||||||
backlinks=[x.wikilink for x in db.nodes_by_outlink(node)],
|
backlinks=n.back_links(),
|
||||||
pushlinks=n.push_links() if n else [],
|
pushlinks=n.push_links() if n else [],
|
||||||
pull_nodes=n.pull_nodes() if n else [],
|
pull_nodes=n.pull_nodes() if n else [],
|
||||||
forwardlinks=n.forward_links() if n else [],
|
forwardlinks=n.forward_links() if n else [],
|
||||||
search=search_subnodes,
|
search=search_subnodes,
|
||||||
|
pulling_nodes=n.pulling_nodes(),
|
||||||
query=n.wikilink.replace('-', '%20')
|
query=n.wikilink.replace('-', '%20')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
19
app/db.py
19
app/db.py
|
@ -118,6 +118,10 @@ class Node:
|
||||||
links.extend(subnode.go())
|
links.extend(subnode.go())
|
||||||
return links
|
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):
|
def forward_links(self):
|
||||||
links = []
|
links = []
|
||||||
for subnode in self.subnodes:
|
for subnode in self.subnodes:
|
||||||
|
@ -127,17 +131,32 @@ class Node:
|
||||||
# Pattern: (subject).action_object.
|
# Pattern: (subject).action_object.
|
||||||
# Could be modeled with RDF?
|
# Could be modeled with RDF?
|
||||||
def pull_nodes(self):
|
def pull_nodes(self):
|
||||||
|
# the nodes *being pulled* by this node.
|
||||||
nodes = []
|
nodes = []
|
||||||
for subnode in self.subnodes:
|
for subnode in self.subnodes:
|
||||||
nodes.extend(subnode.pull_nodes())
|
nodes.extend(subnode.pull_nodes())
|
||||||
return sorted(set(nodes), key=lambda x: x.uri)
|
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):
|
def push_links(self):
|
||||||
links = []
|
links = []
|
||||||
for subnode in self.subnodes:
|
for subnode in self.subnodes:
|
||||||
links.extend(subnode.push_links())
|
links.extend(subnode.push_links())
|
||||||
return sorted(set(links))
|
return sorted(set(links))
|
||||||
|
|
||||||
|
def back_links(self):
|
||||||
|
return sorted([x.wikilink for x in nodes_by_outlink(self.wikilink)])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Subnode:
|
class Subnode:
|
||||||
"""A subnode is a note or media resource volunteered by a user of the Agora.
|
"""A subnode is a note or media resource volunteered by a user of the Agora.
|
||||||
|
|
|
@ -34,11 +34,17 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div class="pulllinks">
|
<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 %}
|
{% for node in pull_nodes %}
|
||||||
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<br />
|
<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>
|
||||||
|
|
||||||
<div class="forwardlinks">
|
<div class="forwardlinks">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue