From 9907d45e4f54fe70e8e062f47f75197a3ae1b58e Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 27 Apr 2021 20:53:24 -0700 Subject: iterate on access redirects and landing page implementation Small code refactors and minimal test coverage --- fatcat_scholar/search.py | 11 +++++++---- fatcat_scholar/templates/work.html | 38 +++++++++++++++++++------------------- fatcat_scholar/web.py | 1 + 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'fatcat_scholar') diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index c5fca35..a0cad2c 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -469,14 +469,17 @@ def lookup_fulltext_pdf(sha1: str) -> Optional[dict]: sha1 = sha1.lower() assert len(sha1) == 40 and sha1.isalnum() hits = do_lookup_query( - f'fulltext.file_sha1:{sha1} fulltext.file_mimetype:"application/pdf"' + f'fulltext.file_sha1:{sha1} fulltext.file_mimetype:"application/pdf" fulltext.access_url:*' ) if not hits.results: return None fulltext = ScholarFulltext.parse_obj(hits.results[0]["fulltext"]) if not fulltext.access_type in ("ia_file", "wayback"): return None - assert fulltext.file_sha1 == sha1 - assert fulltext.file_mimetype == "application/pdf" - assert fulltext.access_url + if fulltext.file_sha1 != sha1: + return None + if fulltext.file_mimetype != "application/pdf": + return None + if not fulltext.access_url: + return None return fulltext diff --git a/fatcat_scholar/templates/work.html b/fatcat_scholar/templates/work.html index 92e334e..067d23c 100644 --- a/fatcat_scholar/templates/work.html +++ b/fatcat_scholar/templates/work.html @@ -2,39 +2,39 @@ {% extends "base.html" %} {% block title %} -{{ doc.title }} +{{ work.title }} {% endblock %} {% block extra_head %} - + - -{% for contrib in doc.biblio.contrib_names %} + +{% for contrib in work.biblio.contrib_names %} {% endfor %} -{% if doc.biblio.release_date or doc.biblio.release_year %} - +{% if work.biblio.release_date or work.biblio.release_year %} + {% endif %} -{% if doc.biblio.container_name %} - +{% if work.biblio.container_name %} + {% endif %} -{% if doc.biblio.volume %} - +{% if work.biblio.volume %} + {% endif %} -{% if doc.biblio.issue %} - +{% if work.biblio.issue %} + {% endif %} -{% if doc.biblio.pages %} - +{% if work.biblio.pages %} + {% endif %} -{% if doc.biblio.doi %} - +{% if work.biblio.doi %} + {% endif %} -{% if doc.fulltext.access_url and doc.biblio.release_ident == doc.fulltext.release_ident and doc.fulltext.access_type in ['wayback', 'ia_file'] and doc.fulltext.file_mimetype == "application/pdf" and doc.fulltext.file_sha1 %} +{% if work.fulltext.access_url and work.biblio.release_ident == work.fulltext.release_ident and work.fulltext.access_type in ['wayback', 'ia_file'] and work.fulltext.file_mimetype == "application/pdf" and work.fulltext.file_sha1 %} - - + + {% endif %} {% endblock %} diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index 56f2561..adddcbd 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -380,6 +380,7 @@ def web_work( "locale": lang.code, "lang_prefix": lang.prefix, "doc": doc, + "work": doc["_obj"], }, ) -- cgit v1.2.3