Add very basic GET-based /search.
This commit is contained in:
parent
a74bef14fa
commit
1e8fbdcf77
3 changed files with 17 additions and 0 deletions
|
@ -71,14 +71,20 @@ def wikilink(node):
|
||||||
def subnode(subnode):
|
def subnode(subnode):
|
||||||
return render_template('subnode_rendered.html', subnode=db.subnode_by_uri(subnode), backlinks=db.subnodes_by_outlink(subnode))
|
return render_template('subnode_rendered.html', subnode=db.subnode_by_uri(subnode), backlinks=db.subnodes_by_outlink(subnode))
|
||||||
|
|
||||||
|
@bp.route('/search/<query>')
|
||||||
|
def search(query):
|
||||||
|
return render_template('subnodes.html', subnodes=db.search_subnodes(query))
|
||||||
|
|
||||||
@bp.route('/asset/<user>/<asset>')
|
@bp.route('/asset/<user>/<asset>')
|
||||||
def asset(user, asset):
|
def asset(user, asset):
|
||||||
# An asset is a binary in someone's garden/<user>/assets directory.
|
# An asset is a binary in someone's garden/<user>/assets directory.
|
||||||
|
# Currently unused.
|
||||||
path = '/'.join(["garden", user, 'assets', asset])
|
path = '/'.join(["garden", user, 'assets', asset])
|
||||||
return current_app.send_static_file(path)
|
return current_app.send_static_file(path)
|
||||||
|
|
||||||
@bp.route('/raw/<node>')
|
@bp.route('/raw/<node>')
|
||||||
def raw(node):
|
def raw(node):
|
||||||
|
# Currently unused.
|
||||||
# hack hack
|
# hack hack
|
||||||
# outlinks
|
# outlinks
|
||||||
return Response("\n\n".join([str(n.outlinks) for n in db.nodes_by_wikilink(node)]), mimetype="text/plain")
|
return Response("\n\n".join([str(n.outlinks) for n in db.nodes_by_wikilink(node)]), mimetype="text/plain")
|
||||||
|
@ -87,4 +93,5 @@ def raw(node):
|
||||||
|
|
||||||
@bp.route('/backlinks/<node>')
|
@bp.route('/backlinks/<node>')
|
||||||
def backlinks(node):
|
def backlinks(node):
|
||||||
|
# Currently unused.
|
||||||
return render_template('nodes.html', nodes=db.nodes_by_outlink(node))
|
return render_template('nodes.html', nodes=db.nodes_by_outlink(node))
|
||||||
|
|
|
@ -173,6 +173,10 @@ def subnodes_by_wikilink(wikilink, fuzzy_matching=True):
|
||||||
subnodes = [subnode for subnode in all_subnodes() if subnode.wikilink == wikilink]
|
subnodes = [subnode for subnode in all_subnodes() if subnode.wikilink == wikilink]
|
||||||
return subnodes
|
return subnodes
|
||||||
|
|
||||||
|
def search_subnodes(query):
|
||||||
|
subnodes = [subnode for subnode in all_subnodes() if re.search(query, subnode.content)]
|
||||||
|
return subnodes
|
||||||
|
|
||||||
def subnodes_by_user(user):
|
def subnodes_by_user(user):
|
||||||
subnodes = [subnode for subnode in all_subnodes() if subnode.user == user]
|
subnodes = [subnode for subnode in all_subnodes() if subnode.user == user]
|
||||||
return subnodes
|
return subnodes
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
<h1> Subnodes </h1>
|
<h1> Subnodes </h1>
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if not subnodes %}
|
||||||
|
No subnodes found for the given term or path.
|
||||||
|
<br /><br />
|
||||||
|
Go back to <a href="/nodes">/nodes</a>?
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% for subnode in subnodes %}
|
{% for subnode in subnodes %}
|
||||||
(user: {{subnode.user}}) {{ subnode.uri }}: <a href="{{subnode.url}}">{{subnode.wikilink}}</a><br />
|
(user: {{subnode.user}}) {{ subnode.uri }}: <a href="{{subnode.url}}">{{subnode.wikilink}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue