aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/routes.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-06-05 15:56:52 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-06-05 15:56:52 -0700
commit388503d92ff8a1f26a0376cc42cefb077a1d6401 (patch)
treeb2329cb6951bfbc5f98a0663f2e4b7991a1949ca /python/fatcat_web/routes.py
parent805a8b1001754fb8397e539dbc15a6cfd65661f2 (diff)
downloadfatcat-388503d92ff8a1f26a0376cc42cefb077a1d6401.tar.gz
fatcat-388503d92ff8a1f26a0376cc42cefb077a1d6401.zip
more lookup views
Diffstat (limited to 'python/fatcat_web/routes.py')
-rw-r--r--python/fatcat_web/routes.py84
1 files changed, 74 insertions, 10 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 5fef1b96..7ddd8cca 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -39,13 +39,32 @@ def container_lookup():
for key in ('issnl', 'wikidata_qid'):
if request.args.get(key):
extid = key
- break
+ extid_value = request.args.get(extid)
+ if extid_value:
+ extid_value = extid_value.strip()
+ break
if extid is None:
- abort(400)
+ return render_template('container_lookup.html')
try:
resp = api.lookup_container(**{extid: request.args.get(extid)})
+ except ValueError:
+ return make_response(
+ render_template('container_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=400),
+ 400)
except ApiException as ae:
- abort(ae.status)
+ if ae.status == 404 or ae.status == 400:
+ return make_response(
+ render_template('container_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=ae.status),
+ ae.status)
+ else:
+ app.log.info(ae)
+ abort(ae.status)
return redirect('/container/{}'.format(resp.ident))
@app.route('/container/<ident>', methods=['GET'])
@@ -92,13 +111,32 @@ def creator_lookup():
for key in ('orcid', 'wikidata_qid'):
if request.args.get(key):
extid = key
- break
+ extid_value = request.args.get(extid)
+ if extid_value:
+ extid_value = extid_value.strip()
+ break
if extid is None:
- abort(400)
+ return render_template('creator_lookup.html')
try:
- resp = api.lookup_creator(**{extid: request.args.get(extid)})
+ resp = api.lookup_creator(**{extid: extid_value})
+ except ValueError:
+ return make_response(
+ render_template('creator_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=400),
+ 400)
except ApiException as ae:
- abort(ae.status)
+ if ae.status == 404 or ae.status == 400:
+ return make_response(
+ render_template('creator_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=ae.status),
+ ae.status)
+ else:
+ app.log.info(ae)
+ abort(ae.status)
return redirect('/creator/{}'.format(resp.ident))
@app.route('/creator/<ident>', methods=['GET'])
@@ -133,13 +171,32 @@ def file_lookup():
for key in ('md5', 'sha1', 'sha256'):
if request.args.get(key):
extid = key
- break
+ extid_value = request.args.get(extid)
+ if extid_value:
+ extid_value = extid_value.strip()
+ break
if extid is None:
- abort(400)
+ return render_template('file_lookup.html')
try:
resp = api.lookup_file(**{extid: request.args.get(extid)})
+ except ValueError:
+ return make_response(
+ render_template('file_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=400),
+ 400)
except ApiException as ae:
- abort(ae.status)
+ if ae.status == 404 or ae.status == 400:
+ return make_response(
+ render_template('file_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=ae.status),
+ ae.status)
+ else:
+ app.log.info(ae)
+ abort(ae.status)
return redirect('/file/{}'.format(resp.ident))
@app.route('/file/<ident>', methods=['GET'])
@@ -231,6 +288,13 @@ def release_lookup():
return render_template('release_lookup.html')
try:
resp = api.lookup_release(**{extid: extid_value})
+ except ValueError:
+ return make_response(
+ render_template('release_lookup.html',
+ lookup_key=extid,
+ lookup_value=extid_value,
+ lookup_error=400),
+ 400)
except ApiException as ae:
if ae.status == 404 or ae.status == 400:
return make_response(