aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/ref_routes.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2021-04-15 18:34:11 -0700
committerBryan Newbold <bnewbold@robocracy.org>2021-07-23 10:55:09 -0700
commitd5b24df069fc96d396afbb302633a077e5dbfb39 (patch)
tree10d8722237efd7074d98d4ee2a1cd3c17cd05926 /python/fatcat_web/ref_routes.py
parenta5a8811a605080f2cd9eb575c33a17f045c43674 (diff)
downloadfatcat-d5b24df069fc96d396afbb302633a077e5dbfb39.tar.gz
fatcat-d5b24df069fc96d396afbb302633a077e5dbfb39.zip
first iteration of basic citation inbound/outbound views
Diffstat (limited to 'python/fatcat_web/ref_routes.py')
-rw-r--r--python/fatcat_web/ref_routes.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/python/fatcat_web/ref_routes.py b/python/fatcat_web/ref_routes.py
new file mode 100644
index 00000000..a49813c4
--- /dev/null
+++ b/python/fatcat_web/ref_routes.py
@@ -0,0 +1,50 @@
+"""
+Flask endpoints for reference (citation) endpoints. Eg, listing references
+"inbound" and "outbound" from a specific release or work.
+"""
+
+from typing import Optional
+
+from flask import render_template, abort, redirect, request
+from fatcat_openapi_client import *
+from fatcat_openapi_client.rest import ApiException
+
+from fatcat_tools.references import enrich_inbound_refs_fatcat, enrich_outbound_refs_fatcat, get_inbound_refs, get_outbound_refs
+from fatcat_web import app, api, auth_api
+from fatcat_web.forms import *
+from fatcat_web.entity_helpers import *
+
+
+@app.route('/release/<string(length=26):ident>/refs/inbound', methods=['GET'])
+def release_view_refs_inbound(ident):
+
+ # lookup release ident, ensure it exists
+ try:
+ release = api.get_release(ident)
+ except ApiException as ae:
+ abort(ae.status)
+
+ offset = request.args.get('offset', '0')
+ offset = max(0, int(offset)) if offset.isnumeric() else 0
+
+ hits = get_inbound_refs(release_ident=ident, es_client=app.es_client, offset=offset, limit=30)
+ enriched_refs = enrich_inbound_refs_fatcat(hits.result_refs, fatcat_api_client=api, expand="container,files,webcaptures")
+
+ return render_template('release_view_fuzzy_refs.html', direction="inbound", entity=release, hits=hits, enriched_refs=enriched_refs), 200
+
+@app.route('/release/<string(length=26):ident>/refs/outbound', methods=['GET'])
+def release_view_refs_outbound(ident):
+
+ # lookup release ident, ensure it exists
+ try:
+ release = api.get_release(ident)
+ except ApiException as ae:
+ abort(ae.status)
+
+ offset = request.args.get('offset', '0')
+ offset = max(0, int(offset)) if offset.isnumeric() else 0
+
+ hits = get_outbound_refs(release_ident=ident, es_client=app.es_client, offset=offset, limit=30)
+ enriched_refs = enrich_outbound_refs_fatcat(hits.result_refs, fatcat_api_client=api, expand="container,files,webcaptures")
+
+ return render_template('release_view_fuzzy_refs.html', direction="outbound", entity=release, hits=hits, enriched_refs=enriched_refs), 200