Fix bug in index and improve node resolution slightly (needs cleanup).
This commit is contained in:
parent
f86bf64385
commit
e9628a2b3a
2 changed files with 13 additions and 11 deletions
16
app/agora.py
16
app/agora.py
|
@ -27,14 +27,17 @@ bp = Blueprint('agora', __name__)
|
|||
@bp.route('/')
|
||||
def index():
|
||||
node='index'
|
||||
n = db.wikilink_to_node(node)
|
||||
return render_template(
|
||||
'node_rendered.html',
|
||||
wikilink=node,
|
||||
subnodes=util.rank(db.subnodes_by_wikilink(node),
|
||||
user='agora'),
|
||||
backlinks=[x.wikilink for x in db.nodes_by_outlink(node)],
|
||||
forwardlinks=n.forward_links() if n else [],
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/help')
|
||||
def help():
|
||||
current_app.logger.warning('Not implemented.')
|
||||
|
@ -98,22 +101,13 @@ def pull(node):
|
|||
return redirect('/node/{}'.format(node))
|
||||
|
||||
|
||||
|
||||
# Entities
|
||||
@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
|
||||
|
||||
n = db.wikilink_to_node(node)
|
||||
return render_template(
|
||||
'node_rendered.html',
|
||||
wikilink=node,
|
||||
|
|
|
@ -264,6 +264,14 @@ def nodes_by_wikilink(wikilink):
|
|||
nodes = [node for node in all_nodes() if node.wikilink == wikilink]
|
||||
return nodes
|
||||
|
||||
def wikilink_to_node(node):
|
||||
try:
|
||||
return nodes_by_wikilink(node)[0]
|
||||
except (KeyError, IndexError):
|
||||
# We'll handle 404 in the template, as we want to show backlinks to non-existent nodes.
|
||||
return False
|
||||
|
||||
|
||||
def subnodes_by_wikilink(wikilink, fuzzy_matching=True):
|
||||
if fuzzy_matching:
|
||||
# TODO
|
||||
|
|
Loading…
Reference in a new issue