Skip to content

Commit

Permalink
fix: identifier for person
Browse files Browse the repository at this point in the history
        * Fix: use identifier_for_person as href

Signed-off-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Sep 24, 2018
1 parent f166092 commit 14ddd04
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 51 deletions.
5 changes: 0 additions & 5 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,6 @@ def _(x):
#: Persons
RERO_ILS_PERSONS_MEF_SCHEMA = 'persons/mef-person-v0.0.1.json'
RERO_ILS_PERSONS_SOURCES = ['rero', 'bnf', 'gnd']
RERO_ILS_PERSONS_PERMALINK = {
'bnf': 'https://catalogue.bnf.fr/ark:/12148/{pid}',
'gnd': 'http://d-nb.info/gnd/{pid}',
'rero': 'http://data.rero.ch/02-{pid}'
}

RERO_ILS_PERSONS_LABEL_ORDER = {
'fallback': 'fr',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{% set data = record.dumps() | person_merge_data_values %}
{% set record = record.dumps() %}
{% set data = record | person_merge_data_values %}

{{ build_row_merged('Birth date', data.date_of_birth) }}
{{ build_row_merged('Death date', data.date_of_death) }}
{{ build_row_merged('Language of person', data.language_of_person) }}
{{ build_row_merged('Gender', data.gender) }}
{{ build_row_merged('Biographical information', data.biographical_information) }}
{{ build_row_permalink_merged('ID', data.pid) }}
{{ build_row_permalink_merged('ID', record) }}
{{ build_row_merged('Name', data.preferred_name_for_person) }}
{{ build_row_merged('Variant name', data.variant_name_for_person) }}
{{ build_row_merged('Authorized access point', data.authorized_access_point_representing_a_person) }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{ build_row('Language of person', data.language_of_person) }}
{{ build_row('Gender', data.gender) }}
{{ build_row('Biographical information', data.biographical_information) }}
{{ build_row_permalink('ID', data, source_name) }}
{{ build_row_permalink('ID', data) }}
{{ build_row('Name', data.preferred_name_for_person) }}
{{ build_row('Variant name', data.variant_name_for_person) }}
{{ build_row('Authorized access point', data.authorized_access_point_representing_a_person) }}
Original file line number Diff line number Diff line change
Expand Up @@ -98,39 +98,37 @@ <h1>{{ record | person_label(current_i18n.language) }}</h1>
{% endif %}
{% endmacro %}

{% macro build_row_permalink(name, data, source_name) %}
{% macro build_row_permalink(name, data) %}
{% if data.pid %}
<div class="row">
<div class="col-xs-2">
{{_(name)}}
</div>
<div class="col-xs-9">
<a target="_blank" href="{{ data | person_id_permalink(source_name) }}">{{ data.pid }}</a>
<a target="_blank" href="{{ data.identifier_for_person }}">{{ data.pid }}</a>
</div>
</div>
{% endif %}
{% endmacro %}

{% macro build_row_permalink_merged(name, values) %}
{% if values %}
<div class="row margin-bottom-20">
<div class="col-xs-2">
{{_(name)}}
</div>
<div class="col-xs-9">
<ul class="list-unstyled">
{% for element in values %}
<li>
{% for source in values[element] %}
<a target="_blank" href="{{ {'pid': element} | person_id_permalink(source) }}">{{ element }}</a>
<span class="label label-default text-uppercase">{{ source }}</span>
{% endfor %}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% macro build_row_permalink_merged(name, record) %}
<div class="row margin-bottom-20">
<div class="col-xs-2">
{{ _(name) }}
</div>
<div class="col-xs-9">
<ul class="list-unstyled">
{% for source in config.RERO_ILS_PERSONS_SOURCES %}
{% if record[source] %}
<li>
<a target="_blank" href="{{ record[source].identifier_for_person }}">{{ record[source].pid }}</a>
<span class="label label-default text-uppercase">{{ source }}</span>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
{% endmacro %}

{% block javascript %}
Expand Down
10 changes: 0 additions & 10 deletions rero_ils/modules/persons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,3 @@ def person_label(data, language):
if label:
return label
return '-'


@blueprint.app_template_filter()
def person_id_permalink(data, source_name):
"""Create permalink."""
permalinks = current_app.config.get('RERO_ILS_PERSONS_PERMALINK', [])
permalink = permalinks.get(source_name, None)
if permalink:
permalink = permalink.format(**data)
return permalink
12 changes: 1 addition & 11 deletions tests/modules/persons/test_persons_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

"""Jinja2 filters tests."""

from rero_ils.modules.persons.views import person_id_permalink, person_label, \
from rero_ils.modules.persons.views import person_label, \
person_merge_data_values


Expand All @@ -46,13 +46,3 @@ def test_person_label(app, person_data):
assert label == 'Cavalieri, Giovanni Battista'
label = person_label(person_data, 'it')
assert label == 'Cavalieri, Giovanni Battista'


def test_person_id_permalink(app):
"""Test person id permalink."""
app.config['RERO_ILS_PERSONS_PERMALINK'] = {
'rero': 'http://data.rero.ch/02-{pid}'
}
data = {"pid": "A023655346"}
permalink = person_id_permalink(data, 'rero')
assert permalink == 'http://data.rero.ch/02-A023655346'

0 comments on commit 14ddd04

Please sign in to comment.