Skip to content

Commit

Permalink
documents: add a configuration for links on identifiers
Browse files Browse the repository at this point in the history
* Closes rero#711.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Mar 2, 2022
1 parent 7dbe2f6 commit c198b6f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
12 changes: 12 additions & 0 deletions sonar/config_sonar.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,15 @@

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_'
}
}
17 changes: 3 additions & 14 deletions sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -97,10 +97,7 @@ <h4 class="m-0">
<li class="creator {{ 'd-none' if loop.index > 3 }}">
{{ contribution | contribution_text }}
{% if contribution.agent.get('identifiedBy', {}).get('value') %}
<a href="https://orcid.org/{{ contribution.agent.identifiedBy.value }}" target="_blank"
class="badge badge-secondary text-light">
ORCID
</a>
{{ identifier_link(contribution.agent.identifiedBy, 'agent')}}
{% endif %}

{% if contribution.get('affiliation') %}
Expand Down Expand Up @@ -261,15 +258,7 @@ <h5 class="d-inline">
<ul class="list-unstyled mb-0">
{% for identifier in record.identifiedBy %}
<li>
<span class="badge badge-secondary text-light mr-1">{{ _(identifier.type) }}</span>
{% if identifier.type == 'bf:Doi' %}
<a href="https://doi.org/{{ identifier.value }}" target="_blank">{{ identifier.value }}</a>
{% else %}
{{ identifier.value }}
{% endif %}
{% if identifier.source %}
<i class="text-muted ml-1">{{ identifier.source }}</i>
{% endif %}
{{ identifier_link(identifier, 'identifiedBy') }}
</li>
{% endfor %}
</ul>
Expand Down
32 changes: 32 additions & 0 deletions sonar/theme/templates/sonar/macros/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,35 @@
<img src="{{ image }}" class="img-fluid" alt="{{ 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 %}
<span class="badge badge-secondary text-light mr-1">{{ identifier.source|upper if identifier.source else _(identifier.type) }}</span>
{% if link %}
<a href="{{ link }}" title="{{ linkText }}" target="_blank">{{ identifier.value }}</a>
{% else %}
{{ identifier.value }}
{% endif %}
{% endif %}

{% if 'agent' == field %}
{% if link %}
<a class="badge badge-secondary text-light mr-1" href="{{ link }}" title="{{ linkText }}" target="_blank">
{{ identifier.source|upper if identifier.source else _(identifier.type) }}
</a>
{% else %}
<span class="badge badge-secondary text-light mr-1">{{ identifier.source|upper if identifier.source else _(identifier.type) }}</span>
{{ identifier.value }}
{% endif %}
{% endif %}
{% endmacro %}
7 changes: 6 additions & 1 deletion sonar/theme/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c198b6f

Please sign in to comment.