Skip to content
Snippets Groups Projects
Commit dcf82bde authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Exploit backend result to update front

parent 5821fc60
No related branches found
No related tags found
No related merge requests found
......@@ -36,26 +36,28 @@ def info():
def public():
"""Main application view.
At the moment, redirect to the content search view.
"""
return redirect(url_for('search'))
@app.route('/public/search')
def search():
"""Search for hashes in swh-storage.
"""
q = request.args.get('q', '')
if q:
flash('Search hash %s posted!' % q)
hashes = query.group_by_checksums(query.parse(q))
api_backend = app.config['conf']['api_backend']
resp_result = service.search(api_backend, hashes)
else:
q = ''
resp_result = []
present = service.search(api_backend, hashes)
return render_template('search.html',
searched_hash=q,
present='Found!' if present else 'Not found!')
return render_template('search.html',
searched_hash=q,
entries=resp_result)
searched_hash='',
present='')
def run(conf):
"""Run the api's server.
......
......@@ -49,10 +49,8 @@ def execute(base_url,
Raises:
None
"""
print(query)
method_fn = query_dispatch[query['method']]
print(method_fn)
res = method_fn(compute_simple_url(base_url, query['url']),
data=query.get('data'),
headers=query.get('headers'))
......@@ -60,7 +58,6 @@ def execute(base_url,
return result_fn(res)
def create_request(method, api_url, data=None):
"""Create a request model without executing it.
......
......@@ -5,6 +5,7 @@
from swh.web.ui.back import http, api_query
import json
def search(base_url, hashes):
......@@ -21,11 +22,16 @@ def search(base_url, hashes):
OSError (no route to host), etc... Network issues in general
"""
def deal_with_result(res):
print("result:", res)
return res.data
if res.ok:
output = res.content.decode('utf-8')
if output:
h_res = json.loads(output)
return h_res['found']
return False
return False
#return []
#return [{'title': 'some title', 'text': 'some text'}]
q = api_query.api_storage_content_present(hashes)
q = api_query.api_storage_content_present({'content': [hashes]})
return http.execute(base_url, q, result_fn=deal_with_result)
......@@ -7,13 +7,7 @@
<dd><input type=submit value=Search>
</dl>
</form>
{% if searched_hash %}
<ul class=entries>
{% for entry in entries %}
<li><h2>{{ entry.title }}</h2>{{ entry.text|safe }}
{% else %}
<li><em>This content has not yet been seen.</em>
{% endfor %}
</ul>
{% endif %}
<ul class=entries>
<li><h2>{{ present | safe }}</h2>
</ul>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment