From 458238533538d22c2bd8bf4a068b7a6bca20b5f6 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Wed, 16 Feb 2022 12:39:20 +0100 Subject: [PATCH] documents: add a configuration for links on identifiers * Closes #711. Co-Authored-by: Bertrand Zuchuat --- sonar/config_sonar.py | 15 ++++++++ .../documents/templates/documents/record.html | 17 ++------- sonar/theme/templates/sonar/macros/macro.html | 35 +++++++++++++++++++ sonar/theme/views.py | 7 +++- tests/ui/test_views.py | 3 ++ 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/sonar/config_sonar.py b/sonar/config_sonar.py index 9e21952c..e36f7feb 100644 --- a/sonar/config_sonar.py +++ b/sonar/config_sonar.py @@ -576,3 +576,18 @@ SONAR_APP_SWISSCOVERY_SEARCH_URL = 'https://swisscovery.slsp.ch/view/sru/41SLSP_NETWORK' SONAR_APP_SWISSCOVERY_SEARCH_VERSION = '1.1' + +# Link on document identifier +# Add the source identifier in lowercase (Ex: orcid) +SONAR_APP_DOCUMENT_IDENTIFIER_LINK = { + 'bf:Doi': { + 'default': 'https://doi.org/_identifier_' + }, + 'bf:Local': { + 'orcid': 'https://orcid.org/_identifier_', + 'swisscovery': 'https://swisscovery.slsp.ch/permalink/41SLSP_NETWORK/1ufb5t2/alma_identifier_' + }, + 'bf:Urn': { + 'default': 'https://nbn-resolving.org/_identifier_' + } +} diff --git a/sonar/modules/documents/templates/documents/record.html b/sonar/modules/documents/templates/documents/record.html index 0a45bf2a..3304f080 100644 --- a/sonar/modules/documents/templates/documents/record.html +++ b/sonar/modules/documents/templates/documents/record.html @@ -18,7 +18,7 @@ {%- extends config.RECORDS_UI_BASE_TEMPLATE %} -{% from 'sonar/macros/macro.html' import thumbnail %} +{% from 'sonar/macros/macro.html' import thumbnail, identifier_link %} {% set title = record.title[0] | title_format(current_i18n.language) %} {% set description = record.abstracts[0].value if record.abstracts else None %} @@ -97,10 +97,7 @@

  • {{ contribution | contribution_text }} {% if contribution.agent.get('identifiedBy', {}).get('value') %} - - ORCID - + {{ identifier_link(contribution.agent.identifiedBy, 'agent')}} {% endif %} {% if contribution.get('affiliation') %} @@ -261,15 +258,7 @@
      {% for identifier in record.identifiedBy %}
    • - {{ _(identifier.type) }} - {% if identifier.type == 'bf:Doi' %} - {{ identifier.value }} - {% else %} - {{ identifier.value }} - {% endif %} - {% if identifier.source %} - {{ identifier.source }} - {% endif %} + {{ identifier_link(identifier, 'identifiedBy') }}
    • {% endfor %}
    diff --git a/sonar/theme/templates/sonar/macros/macro.html b/sonar/theme/templates/sonar/macros/macro.html index 263fee34..a61fd972 100644 --- a/sonar/theme/templates/sonar/macros/macro.html +++ b/sonar/theme/templates/sonar/macros/macro.html @@ -62,3 +62,38 @@ {{ label }} {% endif%} {% endmacro %} + +{% macro identifier_link(identifier, field) %} +{% set linkText = _('External link to the source') %} +{% if identifier.type in config.SONAR_APP_DOCUMENT_IDENTIFIER_LINK %} + {% set source = 'default' if not identifier.source else identifier.source|lower %} + {% if source in config.SONAR_APP_DOCUMENT_IDENTIFIER_LINK[identifier.type] %} + {% set link = config.SONAR_APP_DOCUMENT_IDENTIFIER_LINK[identifier.type][source].replace('_identifier_', identifier.value) %} + {% else %} + {% set link = null %} + {% endif %} +{% endif %} + +{% if 'identifiedBy' == field %} + {{ identifier.source|upper if identifier.source else _(identifier.type)|upper }} + {% if link %} + {{ identifier.value }} + {% else %} + {% if identifier.value.startswith('http') %} + {{ identifier.value }} + {% else %} + {{ identifier.value }} + {% endif %} + {% endif %} +{% endif %} + +{% if 'agent' == field %} + {% if link %} + + {{ identifier.source|upper if identifier.source else _(identifier.type) }} + + {% else %} + {{ identifier.source|upper if identifier.source else _(identifier.type)|upper }} + {% endif %} +{% endif %} +{% endmacro %} diff --git a/sonar/theme/views.py b/sonar/theme/views.py index 8f0d8b67..e8a1a433 100644 --- a/sonar/theme/views.py +++ b/sonar/theme/views.py @@ -151,7 +151,12 @@ def logged_user(): if user and 'resolve' in request.args: user = user.replace_refs() - data = {} + data = { + 'settings': { + 'document_identifier_link': current_app.config \ + .get('SONAR_APP_DOCUMENT_IDENTIFIER_LINK') + } + } if user: data['metadata'] = user.dumps() diff --git a/tests/ui/test_views.py b/tests/ui/test_views.py index 7540b4a7..6a9a387b 100644 --- a/tests/ui/test_views.py +++ b/tests/ui/test_views.py @@ -81,6 +81,9 @@ def test_logged_user(app, client, superuser, admin, moderator, submitter, assert b'"email":"orgadmin@rero.ch"' in res.data assert b'"pid":"org"' in res.data + # Check settings + assert 'settings' in res.json + # Logged as superuser login_user_via_session(client, email=superuser['email']) res = client.get(url)