summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-04-04 12:24:46 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-04-04 12:24:46 -0700
commit7d90315279d02b0d02d566a2b84231986bc43e59 (patch)
treec384d89c6445946cbe4e4f6b16c08955610652e4 /python
parent8409128c47a287ccdf4d5092f094648495367e5a (diff)
downloadfatcat-7d90315279d02b0d02d566a2b84231986bc43e59.tar.gz
fatcat-7d90315279d02b0d02d566a2b84231986bc43e59.zip
more citation styles, and tests
Diffstat (limited to 'python')
-rw-r--r--python/fatcat_web/routes.py2
-rw-r--r--python/fatcat_web/templates/release_view.html3
-rw-r--r--python/tests/web_citation_csl.py8
3 files changed, 12 insertions, 1 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 8e07aff0..32a1837d 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -570,6 +570,8 @@ def release_citeproc(ident):
cite = citeproc_csl(csl, style, is_html)
if is_html:
return Response(cite)
+ elif style == "csl-json":
+ return jsonify(json.loads(cite))
else:
return Response(cite, mimetype="text/plain")
diff --git a/python/fatcat_web/templates/release_view.html b/python/fatcat_web/templates/release_view.html
index ef77360f..ff044c49 100644
--- a/python/fatcat_web/templates/release_view.html
+++ b/python/fatcat_web/templates/release_view.html
@@ -415,6 +415,9 @@
</div>
<div class="content">
<a href="/release/{{ release.ident }}.bib">BibTeX</a>
+ <br><a href="/release/{{ release.ident }}/citeproc?style=csl-json">CSL-JSON</a>
+ <br><a href="/release/{{ release.ident }}/citeproc?style=modern-language-association">MLA</a>
+ <br><a href="/release/{{ release.ident }}/citeproc?style=elsevier-harvard">Harvard</a>
</div>
</div>
{% endif %}
diff --git a/python/tests/web_citation_csl.py b/python/tests/web_citation_csl.py
index 1b6f34e1..ae9bca55 100644
--- a/python/tests/web_citation_csl.py
+++ b/python/tests/web_citation_csl.py
@@ -1,5 +1,4 @@
-
import json
import tempfile
import pytest
@@ -16,6 +15,13 @@ def test_release_bibtex(app):
rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaam.bib')
assert rv.status_code == 200
assert b'@article{' in rv.data
+ rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaam/citeproc?style=csl-json')
+ assert rv.status_code == 200
+ # could also rv.get_json() here
+ json.loads(rv.data.decode('utf-8'))
+ rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaam/citeproc?style=modern-language-association')
+ assert rv.status_code == 200
+ assert rv.data.decode('utf-8').startswith('Ioannidis. “Why Most Published Research Findings Are False”. 2.8 (2005)')
# "dummy" demo entity
rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaai')