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

Simplify first ui to look a hash up

parent 6093d65c
No related branches found
No related tags found
No related merge requests found
......@@ -31,32 +31,34 @@ def info():
return 'Dev SWH UI'
def lookup_hash(api_backend, query_hash):
"""Lookup a hash in the query.
"""
hashes = query.group_by_checksums(query.parse(query_hash))
if hashes != {}:
present = service.search(api_backend, hashes)
return 'Found!' if present else 'Not Found'
return """This is not a hash.
Hint: hexadecimal string with length either 20 (sha1) or 32 (sha256)."""
@app.route('/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))
if hashes != {}:
api_backend = app.config['conf']['api_backend']
present = service.search(api_backend, hashes)
if present:
message = 'Found!'
else:
message = 'Not found!'
else:
message = """This is not a hash.
Hint: hexadecimal string with length either 20 (sha1) or 32 (sha256)."""
flash("Search hash '%s' posted!" % q)
message = lookup_hash(app.config['conf']['api_backend'], q)
else:
message = ''
return render_template('search.html',
searched_hash=q,
present=message)
return render_template('search.html',
searched_hash='',
present='')
q=q,
message=message)
def run(conf):
"""Run the api's server.
......
......@@ -3,11 +3,11 @@
<form action="{{ url_for('search') }}" method=get class=search>
<dl>
<dt>Hashes (colon separated values):
<dd><input type=text size=32 name=q value={{ searched_hash }}>
<dd><input type=text size=32 name=q value={{ q }}>
<dd><input type=submit value=Search>
</dl>
</form>
<ul class=entries>
<li><h2>{{ present | safe }}</h2>
<li><h2>{{ message | 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