From 662a328047b67c039d73406d3aad7286f595c984 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 11 Feb 2016 15:42:31 +0100 Subject: [PATCH] Now list cited papers that could be uploaded to an OA repository --- main.py | 29 +++++++++++++++++++++++------ requirements.txt | 2 +- views/template.tpl | 17 ++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index baca1e1..9dcb7a4 100755 --- a/main.py +++ b/main.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import config import html -import json import os import tempfile @@ -10,6 +9,28 @@ from libbmc import doi from libbmc.citations import pdf +def format_citation(doi_url): + if doi_url is None: + return { + "doi": None, + "oa": None, + "sharable": None + } + + canonical_doi = doi.to_canonical(doi_url) + sharable = doi.get_oa_policy(canonical_doi) + if sharable is None: + sharable = False + else: + sharable = "can" in sharable.values() + + return { + "doi": canonical_doi, + "oa": doi.get_oa_version(canonical_doi), + "sharable": sharable + } + + @route("/upload", method="POST") @view("template.tpl") def do_upload(): @@ -36,11 +57,7 @@ def do_upload(): raw_citations = pdf.cermine_dois(fh.name, override_local=config.CERMINE_PATH) citations = { - html.unescape(k): { - "doi": doi.to_canonical(v) if v is not None else v, - "oa": doi.get_oa_version(doi.to_canonical(v) if v is not None - else v) - } + html.unescape(k): format_citation(v) for k, v in raw_citations.items() } diff --git a/requirements.txt b/requirements.txt index b3b5996..0268137 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ bottle>=0.12.9 -libbmc>=0.1.2 +libbmc>=0.1.3.1 diff --git a/views/template.tpl b/views/template.tpl index d8ac27c..9282b7f 100644 --- a/views/template.tpl +++ b/views/template.tpl @@ -27,6 +27,14 @@ dt:not(:first-child) { margin-top: 1em; } + + .red { + text-color: red; + } + + .green { + text-color: green; + } @@ -53,7 +61,14 @@ % if v["oa"] is not None: {{ v["oa"] }} % else: - No OpenAccess version found. + + No OpenAccess version found. + % if v["sharable"]: + It could be shared. + % else: + It could not be shared. + % end + % end % end