Some hacks to do push/pull, but enable only back/forward.
This commit is contained in:
parent
38c35a8220
commit
13853488e3
18
app/agora.py
18
app/agora.py
|
@ -96,14 +96,26 @@ def pull(node):
|
|||
@bp.route('/node/<node>')
|
||||
@bp.route('/wikilink/<node>') # alias for now
|
||||
def wikilink(node):
|
||||
|
||||
try:
|
||||
n = db.nodes_by_wikilink(node)
|
||||
except KeyError:
|
||||
# We'll handle 404 in the template, as we want to show backlinks to non-existent nodes.
|
||||
pass
|
||||
|
||||
try:
|
||||
n = n[0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
return render_template(
|
||||
'node_rendered.html',
|
||||
wikilink=node,
|
||||
subnodes=db.subnodes_by_wikilink(node),
|
||||
backlinks=db.subnodes_by_outlink(node),
|
||||
# pushlinks=db.subnodes_by_pushlink(node),
|
||||
# pulllinks=db.subnodes_by_pulllink(node),
|
||||
# forwardlinks=db.subnodes_by_outlink(node)
|
||||
pushlinks=n.push_links() if n else [],
|
||||
pulllinks=n.pull_links() if n else [],
|
||||
forwardlinks=n.forward_links() if n else [],
|
||||
)
|
||||
|
||||
@bp.route('/subnode/<path:subnode>')
|
||||
|
|
41
app/db.py
41
app/db.py
|
@ -70,11 +70,29 @@ class Node:
|
|||
|
||||
def go(self):
|
||||
# There's surely a much better way to do this. Alas :)
|
||||
go = []
|
||||
links = []
|
||||
for subnode in self.subnodes:
|
||||
go.extend(subnode.go())
|
||||
links.extend(subnode.go())
|
||||
return go
|
||||
|
||||
def forward_links(self):
|
||||
links = []
|
||||
for subnode in self.subnodes:
|
||||
links.extend(subnode.outlinks)
|
||||
return sorted(set(links))
|
||||
|
||||
def pull_links(self):
|
||||
links = []
|
||||
for subnode in self.subnodes:
|
||||
links.extend(subnode.pull_links())
|
||||
return sorted(set(links))
|
||||
|
||||
def push_links(self):
|
||||
links = []
|
||||
for subnode in self.subnodes:
|
||||
links.extend(subnode.push_links())
|
||||
return sorted(set(links))
|
||||
|
||||
|
||||
class Subnode:
|
||||
"""A subnode is a note or media resource volunteered by a user of the Agora.
|
||||
|
@ -129,7 +147,7 @@ class Subnode:
|
|||
sanitized_golinks.append('https://' + golink)
|
||||
return sanitized_golinks
|
||||
|
||||
def pull(self):
|
||||
def pull_links(self):
|
||||
"""
|
||||
returns a set of pull links contained in this subnode
|
||||
pull links are blocks of the form:
|
||||
|
@ -138,9 +156,24 @@ class Subnode:
|
|||
|
||||
# TODO: test.
|
||||
pull_links = subnode_to_actions(self, 'pull')
|
||||
entities = content_to_outlinks(pull_links)
|
||||
entities = content_to_outlinks("\n".join(pull_links))
|
||||
return entities
|
||||
|
||||
def push_links(self):
|
||||
"""
|
||||
returns a set of push links contained in this subnode
|
||||
push links are blocks of the form:
|
||||
- [[push]] [[node]]
|
||||
|
||||
TODO: refactor with the above.
|
||||
"""
|
||||
|
||||
# TODO: test.
|
||||
push_links = subnode_to_actions(self, 'push')
|
||||
entities = content_to_outlinks("\n".join(push_links))
|
||||
return entities
|
||||
|
||||
|
||||
|
||||
def subnode_to_actions(subnode, action):
|
||||
# hack hack.
|
||||
|
|
|
@ -92,29 +92,25 @@ h2 { font-size: 1.2em; }
|
|||
}
|
||||
|
||||
.backlinks {
|
||||
/*background: #1f1f2f; */
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.pushlinks {
|
||||
/*background: #1f1f2f; */
|
||||
width: 20%;
|
||||
background: #161616;
|
||||
color: #cfcfcf;
|
||||
padding: 0.5em;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.pulllinks, .forwardlinks {
|
||||
/*background: #1f1f2f; */
|
||||
background: #161616;
|
||||
.pulllinks {
|
||||
width: 20%;
|
||||
background: #161616;
|
||||
color: #cfcfcf;
|
||||
padding: 0.5em;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.forwardlinks {
|
||||
background: #161616;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.backlinks-header, .pushlinks-header, .pulllinks-header, .forwardlinks-header {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
<span class="links-header">Links</span><br />
|
||||
<div class="links">
|
||||
{% if backlinks %}
|
||||
<div class="backlinks">
|
||||
<span class="backlinks-header">← back</span><br />
|
||||
{% for subnode in backlinks %}
|
||||
|
@ -24,35 +23,30 @@
|
|||
{% endfor %}
|
||||
<br />
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if pushlinks %}
|
||||
<!--
|
||||
<div class="pushlinks">
|
||||
<span class="pushlinks-header">⇇ push</span><br />
|
||||
{% for subnode in pushlinks %}
|
||||
<a href="{{subnode.url}}">{{subnode.wikilink}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a><br />
|
||||
<span class="pushlinks-header">push</span><br />
|
||||
{% for link in pushlinks %}
|
||||
<a href="/node/{{link}}">{{link}}</a><br />
|
||||
{% endfor %}
|
||||
<br />
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if pulllinks %}
|
||||
|
||||
<div class="pulllinks">
|
||||
<span class="pulllinks-header">⇉ pull</span><br />
|
||||
{% for subnode in pulllinks %}
|
||||
<a href="{{subnode.url}}">{{subnode.wikilink}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a><br />
|
||||
<span class="pulllinks-header">pull</span><br />
|
||||
{% for link in pulllinks %}
|
||||
<a href="/node/{{link}}">{{link}}</a><br />
|
||||
{% endfor %}
|
||||
<br />
|
||||
</div>
|
||||
{% endif %}
|
||||
-->
|
||||
|
||||
{% if forwardlinks %}
|
||||
<div class="forwardlinks">
|
||||
<span class="forwardlinks-header">→ forward</span><br />
|
||||
{% for subnode in forwardlinks %}
|
||||
<a href="{{subnode.url}}">{{subnode.wikilink}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a><br />
|
||||
{% for link in forwardlinks %}
|
||||
<a href="/node/{{link}}">{{link}}</a><br />
|
||||
{% endfor %}
|
||||
<br />
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue