summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web
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
parenta5a8811a605080f2cd9eb575c33a17f045c43674 (diff)
downloadfatcat-d5b24df069fc96d396afbb302633a077e5dbfb39.tar.gz
fatcat-d5b24df069fc96d396afbb302633a077e5dbfb39.zip
first iteration of basic citation inbound/outbound views
Diffstat (limited to 'python/fatcat_web')
-rw-r--r--python/fatcat_web/__init__.py2
-rw-r--r--python/fatcat_web/ref_routes.py50
-rw-r--r--python/fatcat_web/templates/release_view_fuzzy_refs.html95
3 files changed, 146 insertions, 1 deletions
diff --git a/python/fatcat_web/__init__.py b/python/fatcat_web/__init__.py
index 07b4e083..3207bc75 100644
--- a/python/fatcat_web/__init__.py
+++ b/python/fatcat_web/__init__.py
@@ -76,7 +76,7 @@ app.register_blueprint(mwoauth.bp, url_prefix='/auth/wikipedia')
app.es_client = elasticsearch.Elasticsearch(Config.ELASTICSEARCH_BACKEND)
-from fatcat_web import routes, editing_routes, auth, cors, forms
+from fatcat_web import routes, editing_routes, ref_routes, auth, cors, forms
# TODO: blocking on ORCID support in loginpass
if Config.ORCID_CLIENT_ID:
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
diff --git a/python/fatcat_web/templates/release_view_fuzzy_refs.html b/python/fatcat_web/templates/release_view_fuzzy_refs.html
new file mode 100644
index 00000000..bc1fa171
--- /dev/null
+++ b/python/fatcat_web/templates/release_view_fuzzy_refs.html
@@ -0,0 +1,95 @@
+{% set release = entity %}
+{% set entity_view = "references" %}
+{% set entity_type = "release" %}
+{% import "entity_macros.html" as entity_macros %}
+{% extends "entity_base.html" %}
+
+{% block entity_main %}
+
+{% if direction == "inbound" %}
+ <h3>Inbound Matched References</h3>
+ <i>Other releases citing this one</i>
+{% elif direction == "outbound" %}
+ <h3>Outbound Matched References</h3>
+ <i>This release citing other releases</i>
+{% endif %}
+
+<p>Found {{ hits.count_total }} references in {{ hits.query_wall_time_ms }}ms.
+{% if hits.count_total != hits.count_returned %}
+ Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }}
+ {% if hits.offset + hits.limit < hits.count_total %}
+ &nbsp;<a href="?offset={{ hits.offset + hits.limit }}">next...</a>
+ {% endif %}
+{% endif %}
+
+<table class="ui very basic celled table">
+<tbody>
+{% for ref in enriched_refs %}
+ {% set release = ref.release %}
+ <tr><td class="collapsing center aligned">
+ {% if direction == "outbound" %}
+ {% if ref.ref.ref_key %}
+ <code>[{{ ref.ref.ref_key }}]</code>
+ {% endif %}
+ {% endif %}
+ <br><b>{{ ref.ref.match_status }}</b>
+ <br>{{ ref.ref.match_provenance }}
+ <td class="">
+ <b><a href="/release/{{ release.ident }}">{{ release.title }}</a></b>
+ {% if release.release_type not in ["article-journal", "conference-paper"] %}
+ <b>[{{ release.release_type or "unknown-type" }}]</b>
+ {% endif %}
+ <br>
+ {% for contrib in release.contribs[:5] %}
+ {% if contrib.creator %}
+ {{ contrib.creator.display_name }}
+ {% else %}
+ {{ contrib.raw_name }}
+ {% endif %}
+ {% if not loop.last %}, {% endif %}
+ {% endfor %}
+ {% if release.contribs | length > 5 %}(+ more) {%endif %}
+ <br>
+ {% if release.release_year %}{{ release.release_year }} &nbsp;{% endif %}
+ {% if release.container %}
+ <i>{{ release.container.name }}</i>
+ {% elif release.extra and release.extra.container_name %}
+ <i>{{ release.extra.container_name }}</i>
+ {% endif %}
+ {% if release.release_stage != "published" %}
+ &nbsp;<span style="color: brown; font-weight: bold;">{{ release.release_stage or "unpublished" }}</span>
+ {% endif %}
+ </small>
+ <br>
+ {% if release.version %}
+ <span style="color:green">version:{{ release.release_year }}</span>&nbsp;
+ {% endif %}
+ {% if release.number %}
+ <span style="color:green">number:{{ release.number }}</span>&nbsp;
+ {% endif %}
+ {% if release.ext_ids.doi %}
+ <a href="https://doi.org/{{ release.ext_ids.doi }}" style="color:green;">doi:{{ release.ext_ids.doi }}</a>&nbsp;
+ {% endif %}
+ {# TODO: links #}
+ {% if release.ext_ids.arxiv %}
+ <a href="#" style="color:green;">arXiv:{{ release.ext_ids.arxiv }}</a>&nbsp;
+ {% endif %}
+ {% if release.ext_ids.pmcid %}
+ <a href="#" style="color:green;">pmcid:{{ release.ext_ids.pmcid }}</a>&nbsp;
+ {% endif %}
+ {% if release.ext_ids.pmid %}
+ <a href="#" style="color:green;">pmid:{{ release.ext_ids.pmid }}</a>&nbsp;
+ {% endif %}
+ {% if release.ext_ids.dblp %}
+ <a href="#" style="color:green;">dblp:{{ release.ext_ids.dblp }}</a>&nbsp;
+ {% endif %}
+ <td class="">
+ {% if ref.access %}
+ <a href="{{ ref.access[0].access_url}}" class="ui tiny green active button">{{ ref.access[0].access_type.name }}</a>
+ {% endif %}
+{% endfor %}
+</tbody>
+</table>
+
+{% endblock %}
+