Initial implementation of go/node0/node1
This commit is contained in:
parent
36fab28aad
commit
790e815e04
44
app/agora.py
44
app/agora.py
|
@ -84,18 +84,50 @@ def go(node):
|
||||||
|
|
||||||
@bp.route('/push/<node>/<other>')
|
@bp.route('/push/<node>/<other>')
|
||||||
def push(node, other):
|
def push(node, other):
|
||||||
#import pprint
|
|
||||||
#response = []
|
|
||||||
#response.append("node: {}".format(node))
|
|
||||||
#response.append("other: {}".format(other))
|
|
||||||
n = G.node(node)
|
n = G.node(node)
|
||||||
o = G.node(other)
|
o = G.node(other)
|
||||||
pushing = n.pushing(o)
|
pushing = n.pushing(o)
|
||||||
#response.append(pushing)
|
|
||||||
|
|
||||||
#return Response(pprint.pformat(response))
|
|
||||||
return Response(pushing)
|
return Response(pushing)
|
||||||
|
|
||||||
|
# [default action](https://anagora.org/node/default-action)
|
||||||
|
@bp.route('/go/<node0>/<node1>')
|
||||||
|
def default_action(node0, node1):
|
||||||
|
"""Redirects to the URL in the given node in a block that starts with [[<action>]], if there is one."""
|
||||||
|
# TODO(flancian): all node-scoped stuff should move to actually use node objects.
|
||||||
|
# TODO(flancian): make [[go]] call this?
|
||||||
|
try:
|
||||||
|
n0 = db.nodes_by_wikilink(node0)
|
||||||
|
except KeyError:
|
||||||
|
return redirect("https://anagora.org/node/%s" % node0)
|
||||||
|
try:
|
||||||
|
n1 = db.nodes_by_wikilink(node1)
|
||||||
|
except KeyError:
|
||||||
|
return redirect("https://anagora.org/node/%s" % node1)
|
||||||
|
|
||||||
|
if len(n0) == 0 and len(n1) == 0:
|
||||||
|
# No nodes with this name.
|
||||||
|
# Redirect to composite node, which might exist and provides search.
|
||||||
|
return redirect(f'https://anagora.org/node/{node0}-{node1}')
|
||||||
|
|
||||||
|
if len(n0) != 0:
|
||||||
|
links = n0[0].filter(node1)
|
||||||
|
elif len(n1) != 0:
|
||||||
|
links += n1[0].filter(node0)
|
||||||
|
|
||||||
|
if len(links) == 0:
|
||||||
|
# No matching links found.
|
||||||
|
# Redirect to composite node, which might exist and provides search.
|
||||||
|
# TODO(flancian): flash an explanation :)
|
||||||
|
return redirect(f'https://anagora.org/node/{node0}-{node1}')
|
||||||
|
|
||||||
|
if len(links) > 1:
|
||||||
|
# TODO(flancian): to be implemented.
|
||||||
|
# Likely default to one of the links, show all of them but redirect to default within n seconds.
|
||||||
|
current_app.logger.warning('Code to manage nodes with more than one go link is not Not implemented.')
|
||||||
|
|
||||||
|
return redirect(links[0])
|
||||||
|
|
||||||
@bp.route('/jump')
|
@bp.route('/jump')
|
||||||
def jump():
|
def jump():
|
||||||
"""Redirects to a context; in "jump" mode, a node *always* exists (nodes map one to one to all possible queries)."""
|
"""Redirects to a context; in "jump" mode, a node *always* exists (nodes map one to one to all possible queries)."""
|
||||||
|
|
34
app/db.py
34
app/db.py
|
@ -162,6 +162,13 @@ class Node:
|
||||||
links.extend(subnode.go())
|
links.extend(subnode.go())
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
def filter(self, other):
|
||||||
|
# There's surely a much better way to do this. Alas :)
|
||||||
|
links = []
|
||||||
|
for subnode in self.subnodes:
|
||||||
|
links.extend(subnode.filter(other))
|
||||||
|
return links
|
||||||
|
|
||||||
# The following section is particularly confusing.
|
# The following section is particularly confusing.
|
||||||
# Some functions return wikilinks, some return full blown nodes.
|
# Some functions return wikilinks, some return full blown nodes.
|
||||||
# We probably want to converge on the latter.
|
# We probably want to converge on the latter.
|
||||||
|
@ -352,6 +359,26 @@ class Subnode:
|
||||||
sanitized_golinks.append('https://' + golink)
|
sanitized_golinks.append('https://' + golink)
|
||||||
return sanitized_golinks
|
return sanitized_golinks
|
||||||
|
|
||||||
|
def filter(self, other):
|
||||||
|
"""
|
||||||
|
other is a string.
|
||||||
|
returns a set of links contained in this subnode
|
||||||
|
in blocks of the form:
|
||||||
|
- [[other]] protocol://example.org/url
|
||||||
|
|
||||||
|
protocol defaults to https.
|
||||||
|
might pick up magic like resolving social network issues later :)
|
||||||
|
"""
|
||||||
|
links = subnode_to_actions(self, other, blocks_only=True)
|
||||||
|
sanitized_links = []
|
||||||
|
for link in links:
|
||||||
|
if '://' in link:
|
||||||
|
sanitized_links.append(link)
|
||||||
|
else:
|
||||||
|
# hack hack.
|
||||||
|
sanitized_links.append('https://' + link)
|
||||||
|
return sanitized_links
|
||||||
|
|
||||||
def pull_nodes(self):
|
def pull_nodes(self):
|
||||||
"""
|
"""
|
||||||
returns a set of nodes pulled (anagora.org/node/pull) in this subnode
|
returns a set of nodes pulled (anagora.org/node/pull) in this subnode
|
||||||
|
@ -401,11 +428,14 @@ class VirtualSubnode(Subnode):
|
||||||
self.node = self.wikilink
|
self.node = self.wikilink
|
||||||
|
|
||||||
|
|
||||||
def subnode_to_actions(subnode, action):
|
def subnode_to_actions(subnode, action, blocks_only=False):
|
||||||
# hack hack.
|
# hack hack.
|
||||||
if subnode.mediatype != 'text/plain':
|
if subnode.mediatype != 'text/plain':
|
||||||
return []
|
return []
|
||||||
action_regex ='\[\[' + action + '\]\] (.*?)$'
|
if blocks_only:
|
||||||
|
action_regex ='- \[\[' + action + '\]\] (.*?)$'
|
||||||
|
else:
|
||||||
|
action_regex ='\[\[' + action + '\]\] (.*?)$'
|
||||||
content = subnode.content
|
content = subnode.content
|
||||||
actions = []
|
actions = []
|
||||||
for line in content.splitlines():
|
for line in content.splitlines():
|
||||||
|
|
Loading…
Reference in New Issue