diff options
| author | Bryan Newbold <bnewbold@robocracy.org> | 2019-06-05 15:56:52 -0700 | 
|---|---|---|
| committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-06-05 15:56:52 -0700 | 
| commit | 388503d92ff8a1f26a0376cc42cefb077a1d6401 (patch) | |
| tree | b2329cb6951bfbc5f98a0663f2e4b7991a1949ca /python | |
| parent | 805a8b1001754fb8397e539dbc15a6cfd65661f2 (diff) | |
| download | fatcat-388503d92ff8a1f26a0376cc42cefb077a1d6401.tar.gz fatcat-388503d92ff8a1f26a0376cc42cefb077a1d6401.zip | |
more lookup views
Diffstat (limited to 'python')
| -rw-r--r-- | python/fatcat_web/routes.py | 84 | ||||
| -rw-r--r-- | python/fatcat_web/templates/container_lookup.html | 63 | ||||
| -rw-r--r-- | python/fatcat_web/templates/creator_lookup.html | 54 | ||||
| -rw-r--r-- | python/fatcat_web/templates/entity_macros.html | 18 | ||||
| -rw-r--r-- | python/fatcat_web/templates/file_lookup.html | 55 | ||||
| -rw-r--r-- | python/fatcat_web/templates/home.html | 3 | ||||
| -rw-r--r-- | python/fatcat_web/templates/release_lookup.html | 39 | 
7 files changed, 279 insertions, 37 deletions
| diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index 5fef1b96..7ddd8cca 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -39,13 +39,32 @@ def container_lookup():      for key in ('issnl', 'wikidata_qid'):          if request.args.get(key):              extid = key -            break +            extid_value = request.args.get(extid) +            if extid_value: +                extid_value = extid_value.strip() +                break      if extid is None: -        abort(400) +        return render_template('container_lookup.html')      try:          resp = api.lookup_container(**{extid: request.args.get(extid)}) +    except ValueError: +        return make_response( +            render_template('container_lookup.html', +                lookup_key=extid, +                lookup_value=extid_value, +                lookup_error=400), +            400)      except ApiException as ae: -        abort(ae.status) +        if ae.status == 404 or ae.status == 400: +            return make_response( +                render_template('container_lookup.html', +                    lookup_key=extid, +                    lookup_value=extid_value, +                    lookup_error=ae.status), +                ae.status) +        else: +            app.log.info(ae) +            abort(ae.status)      return redirect('/container/{}'.format(resp.ident))  @app.route('/container/<ident>', methods=['GET']) @@ -92,13 +111,32 @@ def creator_lookup():      for key in ('orcid', 'wikidata_qid'):          if request.args.get(key):              extid = key -            break +            extid_value = request.args.get(extid) +            if extid_value: +                extid_value = extid_value.strip() +                break      if extid is None: -        abort(400) +        return render_template('creator_lookup.html')      try: -        resp = api.lookup_creator(**{extid: request.args.get(extid)}) +        resp = api.lookup_creator(**{extid: extid_value}) +    except ValueError: +        return make_response( +            render_template('creator_lookup.html', +                lookup_key=extid, +                lookup_value=extid_value, +                lookup_error=400), +            400)      except ApiException as ae: -        abort(ae.status) +        if ae.status == 404 or ae.status == 400: +            return make_response( +                render_template('creator_lookup.html', +                    lookup_key=extid, +                    lookup_value=extid_value, +                    lookup_error=ae.status), +                ae.status) +        else: +            app.log.info(ae) +            abort(ae.status)      return redirect('/creator/{}'.format(resp.ident))  @app.route('/creator/<ident>', methods=['GET']) @@ -133,13 +171,32 @@ def file_lookup():      for key in ('md5', 'sha1', 'sha256'):          if request.args.get(key):              extid = key -            break +            extid_value = request.args.get(extid) +            if extid_value: +                extid_value = extid_value.strip() +                break      if extid is None: -        abort(400) +        return render_template('file_lookup.html')      try:          resp = api.lookup_file(**{extid: request.args.get(extid)}) +    except ValueError: +        return make_response( +            render_template('file_lookup.html', +                lookup_key=extid, +                lookup_value=extid_value, +                lookup_error=400), +            400)      except ApiException as ae: -        abort(ae.status) +        if ae.status == 404 or ae.status == 400: +            return make_response( +                render_template('file_lookup.html', +                    lookup_key=extid, +                    lookup_value=extid_value, +                    lookup_error=ae.status), +                ae.status) +        else: +            app.log.info(ae) +            abort(ae.status)      return redirect('/file/{}'.format(resp.ident))  @app.route('/file/<ident>', methods=['GET']) @@ -231,6 +288,13 @@ def release_lookup():          return render_template('release_lookup.html')      try:          resp = api.lookup_release(**{extid: extid_value}) +    except ValueError: +        return make_response( +            render_template('release_lookup.html', +                lookup_key=extid, +                lookup_value=extid_value, +                lookup_error=400), +            400)      except ApiException as ae:          if ae.status == 404 or ae.status == 400:              return make_response( diff --git a/python/fatcat_web/templates/container_lookup.html b/python/fatcat_web/templates/container_lookup.html new file mode 100644 index 00000000..1848739a --- /dev/null +++ b/python/fatcat_web/templates/container_lookup.html @@ -0,0 +1,63 @@ +{% extends "base.html" %} +{% import "entity_macros.html" as entity_macros %} + +{% block body %} + +<h1>Lookup Container by Identifier</h1> + +{% if lookup_error == 400 %} +<div class="ui error message"> +<div class="header">400: Syntax Error</div> +<b>{{ lookup_key }}:{{ lookup_value }}</code></b> doesn't look right to us. See +below for details. +</div> +{% elif lookup_error == 404 %} +<div class="ui error message"> +<div class="header">404: Not Found</div> +Couldn't find a container with that identifier (<b><code>{{ lookup_key }}:{{ +lookup_value }}</code></b>). If you think it should be in the catalog, you could +search for an existing record missing that identifier, or create a new container +entity.  +{% if lookup_key == "doi" %} +<p>You can check if it is a registered ISSN-L by visiting: +<b><a href="https://portal.issn.org/{{ lookup_value +}}">https://portal.issn.org/{{ lookup_value }}</a></b>. If this is a valid +electronic or print ISSN, but not the ISSN-L for the container, you need to use +the indicated "linking" ISSN. +{% elif lookup_key == "wikidata_qid" %} +<p>You can check if it is a real Wikidata entity by visiting: +<b><a href="https://www.wikidata.org/wiki/{{ lookup_value }}/">https://www.wikidata.org/wiki/{{ lookup_value }}/</a></b> +{% endif %} +</div> +{% endif %} + +<div class="ui top attached segment"> + +<h2>ISSN-L</h2> +<p>The "linking" ISSN for a journal or other publication is one of the  +"print" or "electronic" +<a href="https://en.wikipedia.org/wiki/International_Standard_Serial_Number#Linking_ISSN">International +Standard Serial Numbers</a>, which has been selected to represent the resource +in all media. It is usually the ISSN which was registered first, and defaults +to the "print" ISSN number for a journal. Fatcat uses ISSN-L as the primary +identifier for journals to reduce confusion and potential for duplication. The +ISSN organization publicly publishes a mapping between linking and +print/electronic ISSNs. +{{ entity_macros.lookup_form("issnl", "1234-567X", lookup_key, lookup_value, lookup_error) }} +<i>  Must include the dash</i> + +</div> +<div class="ui attached bottom segment"> + +<h2>Wikidata QID</h2> +<p><a href="https://en.wikipedia.org/wiki/Wikidata#Items">Wikidata</a> is the +structured, machine-readable database that complements Wikipedia. Entities, +which can include bibliographic entities like books and papers, are identified +by a "QID". Fatcat also links container (journal) and creator (author) entities +to Wikidata by QID. Anybody can edit Wikidata and create QIDs. +{{ entity_macros.lookup_form("wikidata_qid", "Q94324", lookup_key, lookup_value, lookup_error) }} +<i>  Include the "Q" prefix.</i> + +</div> + +{% endblock %} diff --git a/python/fatcat_web/templates/creator_lookup.html b/python/fatcat_web/templates/creator_lookup.html new file mode 100644 index 00000000..741efbda --- /dev/null +++ b/python/fatcat_web/templates/creator_lookup.html @@ -0,0 +1,54 @@ +{% extends "base.html" %} +{% import "entity_macros.html" as entity_macros %} + +{% block body %} + +<h1>Lookup Creator by Identifier</h1> + +{% if lookup_error == 400 %} +<div class="ui error message"> +<div class="header">400: Syntax Error</div> +<b>{{ lookup_key }}:{{ lookup_value }}</code></b> doesn't look right to us. See +below for details. +</div> +{% elif lookup_error == 404 %} +<div class="ui error message"> +<div class="header">404: Not Found</div> +Couldn't find a creator with that identifier (<b><code>{{ lookup_key }}:{{ +lookup_value }}</code></b>). If you think it should be in the catalog, you could +search for an existing record missing that identifier, or create a new creator +entity.  +{% if lookup_key == "orcid" %} +<p>You can check if it is a registered ORCiD: +<b><a href="https://orcid.org/{{ lookup_value }}">https://orcid.org/{{ lookup_value }}</a></b> +{% elif lookup_key == "wikidata_qid" %} +<p>You can check if it is a real Wikidata entity by visiting: +<b><a href="https://www.wikidata.org/wiki/{{ lookup_value }}/">https://www.wikidata.org/wiki/{{ lookup_value }}/</a></b> +{% endif %} +</div> +{% endif %} + +<div class="ui top attached segment"> + +<h2>ORCID</h2> +<p><a href="https://en.wikipedia.org/wiki/ORCID">Open Researcher and +Contributor ID</a> is used to unambiguously refer to a research author. They +are free to register. +{{ entity_macros.lookup_form("creator", "orcid", "0000-0002-1825-0097", lookup_key, lookup_value, lookup_error) }} +<i>  Must include the dashes</i> + +</div> +<div class="ui attached bottom segment"> + +<h2>Wikidata QID</h2> +<p><a href="https://en.wikipedia.org/wiki/Wikidata#Items">Wikidata</a> is the +structured, machine-readable database that complements Wikipedia. Entities, +which can include bibliographic entities like books and papers, are identified +by a "QID". Fatcat also links releases (papers, books) and container (journal) +entities to Wikidata by QID. Anybody can edit Wikidata and create QIDs. +{{ entity_macros.lookup_form("creator", "wikidata_qid", "Q94324", lookup_key, lookup_value, lookup_error) }} +<i>  Include the "Q" prefix.</i> + +</div> + +{% endblock %} diff --git a/python/fatcat_web/templates/entity_macros.html b/python/fatcat_web/templates/entity_macros.html index c47782a8..a2b2f996 100644 --- a/python/fatcat_web/templates/entity_macros.html +++ b/python/fatcat_web/templates/entity_macros.html @@ -96,3 +96,21 @@  </tbody>  </table>  {%- endmacro %} + +{% macro lookup_form(entity_type, key, example, lookup_key, lookup_value, lookup_error) -%} +<form class="ui form" role="search" action="/{{ entity_type }}/lookup" method="get"> +  <div class="ui form"> +    <div class="field {% if key == lookup_key %}{% if lookup_error == 400 %}error{% elif lookup_error == 404 %}warning{% endif %}{% endif %}"> +      {% if key == lookup_key and lookup_error == 400 %} +        <div class="ui pointing below red label"> +          Not correct syntax. Expected, eg, {{ example }} +        </div> +      {% endif %} +      <div class="ui action input big fluid"> +        <input type="text" placeholder="{% if example %}eg, {{ example }}{% endif %}" name="{{ key }}" value="{% if key == lookup_key %}{{ lookup_value }}{% endif %}" aria-label="{{ key }} lookup"> +        <button class="ui button">Go!</button> +      </div> +    </div> +  </div> +</form> +{%- endmacro %} diff --git a/python/fatcat_web/templates/file_lookup.html b/python/fatcat_web/templates/file_lookup.html new file mode 100644 index 00000000..c4255f47 --- /dev/null +++ b/python/fatcat_web/templates/file_lookup.html @@ -0,0 +1,55 @@ +{% extends "base.html" %} +{% import "entity_macros.html" as entity_macros %} + +{% block body %} + +<h1>Lookup File by Hash</h1> + +{% if lookup_error == 400 %} +<div class="ui error message"> +<div class="header">400: Syntax Error</div> +<b>{{ lookup_key }}:{{ lookup_value }}</code></b> doesn't look right to us. See +below for details. +</div> +{% elif lookup_error == 404 %} +<div class="ui error message"> +<div class="header">404: Not Found</div> +Couldn't find a file with that hash (<b><code>{{ lookup_key }}:{{ +lookup_value }}</code></b>). If you think it should be in the catalog, you could +search for an existing record missing that hash, or create a new file +entity.  +</div> +{% endif %} + +<div class="ui top attached segment"> + +<h2>SHA-1, SHA-256, MD5</h2> +<p><a href="https://en.wikipedia.org/wiki/SHA-1">SHA-1</a> and +<a href="https://en.wikipedia.org/wiki/SHA-2">SHA-256</a> are popular +cryptographic message digests. They can be used to detect accidental +corruption, intentional modification, and can be used as unique identifiers for +a file. The chance of there existing multiple files with the same hash is +effectively zero due to random chance; the chance of somebody having +intentionally created files with the same hash depends on the strength of the +hash function. + +<p><b>SHA-256</b> is considered "strong" today and used in new software. +{{ entity_macros.lookup_form("file", "sha256", "cd65a99c0d95f3208f4ea28bc73f641a6901a22dfb882d14d5c208821b56c09c", lookup_key, lookup_value, lookup_error) }} +<i>  Lower-case hexideximal, 64 characters</i> +<br><br> + +<p><b>SHA-1</b> has shown weaknesses, but is used widely in data archiving software. +{{ entity_macros.lookup_form("file", "sha1", "79ed4e54acdd521ca5f7b52a2964c9c116c3e3bf", lookup_key, lookup_value, lookup_error) }} +<i>  Lower-case hexideximal, 40 characters</i> +<br><br> + +<p><b><a href="https://en.wikipedia.org/wiki/MD5">MD5</a></b> is an older but still +commonly used checksum. It was originally designed in 1992 to be +cryptographically secure, but is no longer considered secure in that context. +It is still perfectly adequate for detecting accidental file corruption. +{{ entity_macros.lookup_form("file", "md5", "eebc51dd5684ec7fd07f7ac0c30e7a78", lookup_key, lookup_value, lookup_error) }} +<i>  Lower-case hexideximal, 32 characters</i> + +</div> + +{% endblock %} diff --git a/python/fatcat_web/templates/home.html b/python/fatcat_web/templates/home.html index 23563f07..87968f30 100644 --- a/python/fatcat_web/templates/home.html +++ b/python/fatcat_web/templates/home.html @@ -84,6 +84,7 @@ indexing (aka, linking together of pre-prints and final copies).              <i class="search icon"></i>              <input type="text" placeholder="ISSN-L" name="issnl" aria-label="lookup journal by ISSN-L">            </div> +        <br><a href="/container/lookup">Other Identifiers</a>          </form>  <tr><td><b>Creator</b> @@ -102,6 +103,7 @@ indexing (aka, linking together of pre-prints and final copies).              <i class="search icon"></i>              <input type="text" placeholder="ORCID" name="orcid" aria-label="lookup author by ORCID">            </div> +        <br><a href="/creator/lookup">Other Identifiers</a>          </form>  <tr><td><b>File</b>          <br>specific digital blobs (immutable) @@ -118,6 +120,7 @@ indexing (aka, linking together of pre-prints and final copies).              <i class="search icon"></i>              <input type="text" placeholder="SHA-1" name="sha1" aria-label="lookup file by SHA1">            </div> +        <br><a href="/file/lookup">Other Hashes</a>          </form>  <tr><td><b>File Set</b>          <br>datasets, suplementary materials diff --git a/python/fatcat_web/templates/release_lookup.html b/python/fatcat_web/templates/release_lookup.html index 0495da36..924d70db 100644 --- a/python/fatcat_web/templates/release_lookup.html +++ b/python/fatcat_web/templates/release_lookup.html @@ -1,22 +1,5 @@  {% extends "base.html" %} - -{% macro lookup_form(key, example, lookup_key, lookup_value, lookup_error) -%} -<form class="ui form" role="search" action="/release/lookup" method="get"> -  <div class="ui form"> -    <div class="field {% if key == lookup_key %}{% if lookup_error == 400 %}error{% elif lookup_error == 404 %}warning{% endif %}{% endif %}"> -      {% if key == lookup_key and lookup_error == 400 %} -        <div class="ui pointing below red label"> -          Not correct syntax. Expected, eg, {{ example }} -        </div> -      {% endif %} -      <div class="ui action input big fluid"> -        <input type="text" placeholder="{% if example %}eg, {{ example }}{% endif %}" name="{{ key }}" value="{% if key == lookup_key %}{{ lookup_value }}{% endif %}" aria-label="{{ key }} lookup"> -        <button class="ui button">Go!</button> -      </div> -    </div> -  </div> -</form> -{%- endmacro %} +{% import "entity_macros.html" as entity_macros %}  {% block body %} @@ -41,7 +24,9 @@ entity.  {% elif lookup_key == "pmcid" %}  <p>You can check if it is a real PMCID by visiting:  <b><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/{{ lookup_value }}/">https://www.ncbi.nlm.nih.gov/pmc/articles/{{ lookup_value }}/</a></b> -{% else %} +{% elif lookup_key == "wikidata_qid" %} +<p>You can check if it is a real Wikidata entity by visiting: +<b><a href="https://www.wikidata.org/wiki/{{ lookup_value }}/">https://www.wikidata.org/wiki/{{ lookup_value }}/</a></b>  {% endif %}  </div>  {% endif %} @@ -56,7 +41,7 @@ digital objects. Fatcat doesn't include all DOIs (eg, for granular components  or TV shows), but it should for all complete research publications. DOIs are  generated by publishers, who pay a fee to registrars like Crossref, Datacite,  or JALC. -{{ lookup_form("doi", "10.1234/abc.5489", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "doi", "10.1234/abc.5489", lookup_key, lookup_value, lookup_error) }}  <i>  Don't include a URL like "http://dx.doi.org/"</i>  </div> @@ -68,7 +53,7 @@ catalog of biomedical publications. Catalog updates are published frequently,  and may include deletions. Fatcat currently is only updated with new entries,  it does not delete PMIDs. PubMed is edited by a large staff of trained  catalogers, and has strict inclusion criteria for journals. -{{ lookup_form("pmid", "823835", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "pmid", "823835", lookup_key, lookup_value, lookup_error) }}  <br>  <p><a href="https://en.wikipedia.org/wiki/PubMed_Central#PMCID">PubMed Central @@ -76,7 +61,7 @@ Identifiers (PMCID)</a> reference works deposited in the US (or European) PMC  repositories. Not all works with a PMCID have a PMID. PMCIDs can be versioned  (eg, with a trailing ".2"), but these are rare and most Fatcat releases only  have the non-versioned PMCID. -{{ lookup_form("pmcid", "PMC93932", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "pmcid", "PMC93932", lookup_key, lookup_value, lookup_error) }}  <i>  Include the "PMC" prefix.</i>  </div> @@ -88,7 +73,7 @@ structured, machine-readable database that complements Wikipedia. Entities,  which can include bibliographic entities like books and papers, are identified  by a "QID". Fatcat also links container (journal) and creator (author) entities  to Wikidata by QID. Anybody can edit Wikidata and create QIDs. -{{ lookup_form("wikidata_qid", "Q94324", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "wikidata_qid", "Q94324", lookup_key, lookup_value, lookup_error) }}  <i>  Include the "Q" prefix.</i>  </div> @@ -98,7 +83,7 @@ to Wikidata by QID. Anybody can edit Wikidata and create QIDs.  <p><a href="https://en.wikipedia.org/wiki/Archival_Resource_Key">Archival  Resource Keys</a> are no-cost, distributed identifiers based on URLs. Mostly  used by archival systems (as opposed to publishers or repositories). -{{ lookup_form("ark", "ark:2349/sddd92", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "ark", "ark:2349/sddd92", lookup_key, lookup_value, lookup_error) }}  <i>  Only the identifier part (starting with "ark:"), not the full URL.</i>  </div> @@ -108,7 +93,7 @@ used by archival systems (as opposed to publishers or repositories).  <p><a href="https://en.wikipedia.org/wiki/International_Standard_Book_Number">  International Standard Book Number</a>, assigned to specific published versions  of a book (including ebooks). -{{ lookup_form("isbn13", "978-3-16-148410-0", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "isbn13", "978-3-16-148410-0", lookup_key, lookup_value, lookup_error) }}  <i>  Canonical ISBN-13 number (not ISBN-9), with hyphens</i>  </div> @@ -120,7 +105,7 @@ generated for works deposited in the free arxiv.org pre-print repository.  Identifiers are generated for each version of a work, eg ending in "v3". Fatcat  releases must be versioned; if you don't know the version you can always lookup  "v1" and then look for other releases under the same work. -{{ lookup_form("arxiv", "0706.0001v1 or math-GT/0309136v2", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "arxiv", "0706.0001v1 or math-GT/0309136v2", lookup_key, lookup_value, lookup_error) }}  <i>  Old and new style supported, but version always required for exact lookups.</i>  </div> @@ -133,7 +118,7 @@ are numbers internally assigned to works archived on  number after a <code>10.2307/</code> prefix, but not all works have such a DOI.  Fatcat mostly has JSTOR identifiers for works in the "Early Journal  Collection", which are in the public domain. -{{ lookup_form("jstor", "92492", lookup_key, lookup_value, lookup_error) }} +{{ entity_macros.lookup_form("release", "jstor", "92492", lookup_key, lookup_value, lookup_error) }}  </div> | 
