Skip to content

Commit

Permalink
documents: add search link on the author's name
Browse files Browse the repository at this point in the history
* Closes #744.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Aug 16, 2022
1 parent fbb0f70 commit 51ad7d5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
6 changes: 3 additions & 3 deletions sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2021 RERO
Copyright (C) 2021-2022 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -101,7 +101,7 @@ <h4 class="m-0">
<ul class="list-unstyled m-0">
{% for contribution in contributors %}
<li class="creator {{ 'd-none' if loop.index > 3 }}">
{{ contributors_format(contribution) }}
{{ contributors_format(contribution, view_code) }}
</li>
{% endfor %}
</ul>
Expand Down Expand Up @@ -283,7 +283,7 @@ <h5 class="d-inline">
<ul class="list-unstyled mb-0">
{% for contribution in meettings %}
<li>
{{ contributors_format(contribution) }}
{{ contributors_format(contribution, view_code) }}
</li>
{% endfor %}
</ul>
Expand Down
35 changes: 18 additions & 17 deletions sonar/modules/documents/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Swiss Open Access Repository
# Copyright (C) 2021 RERO
# Copyright (C) 2021-2022 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -308,18 +308,8 @@ def contribution_text(contribution):

# Meeting
if contribution['agent']['type'] == 'bf:Meeting':
meeting = []
if contribution['agent'].get('number'):
meeting.append(contribution['agent']['number'])

if contribution['agent'].get('date'):
meeting.append(contribution['agent']['date'])

if contribution['agent'].get('place'):
meeting.append(contribution['agent']['place'])

if meeting:
data.append('({meeting})'.format(meeting=' : '.join(meeting)))
if meeting := meeting_text(contribution):
data.append(f'({meeting})')

# Person
if contribution['agent'][
Expand All @@ -330,6 +320,19 @@ def contribution_text(contribution):
return ' '.join(data)


@blueprint.app_template_filter()
def meeting_text(contribution):
"""Format the meeting field for display.
:param contribution: Dict representing the contribution.
:returns: Formatted text.
"""
contrib = contribution['agent']
return ' : '.join([
contrib[key] for key in ['number', 'date', 'place']
if key in contrib.keys()])


@blueprint.app_template_filter()
def get_custom_field_label(record, custom_field_index):
"""Get the label of a custom field.
Expand Down Expand Up @@ -359,11 +362,9 @@ def get_language_from_bibliographic_code(language_code):
languages_map = current_app.config.get('SONAR_APP_LANGUAGES_MAP')

if language_code not in languages_map:
raise Exception('Language code not found for "{language_code}"'.format(
language_code=language_code))
raise Exception(f'Language code not found for "{language_code}"')
code = languages_map.get(language_code)
if not code:
return '';
return code or '';

return code

Expand Down
29 changes: 19 additions & 10 deletions sonar/theme/templates/sonar/macros/macro.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2021 RERO
Copyright (C) 2021-2022 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -101,19 +101,28 @@
{% endif %}
{% endmacro %}

{% macro contributors_format(contribution) %}
{{ contribution | contribution_text }}
{% macro contributors_format(contribution, view_code) %}
<!-- contribution name -->
<a href="{{ url_for('documents.search', view=view_code,
q='contribution.agent.preferred_name:' + contribution.agent.preferred_name) }}"
>{{ contribution.agent.preferred_name }}</a>
<!-- meeting -->
{% if contribution.agent.type == 'bf:Meeting' %}
{% set meeting_text = contribution | meeting_text %}
{% if meeting_text %}({{ meeting_text }}){% endif %}
{% endif %}
<!-- role for person -->
{% if contribution.agent.type == 'bf:Person' and contribution.role and contribution.role[0] != 'cre' %}
({{ _('contribution_role_' + contribution.role[0]) | lower }})
{% endif %}
{% if contribution.agent.get('identifiedBy', {}).get('value') %}
{{ identifier_link(contribution.agent.identifiedBy, 'agent')}}
{% endif %}

{% if contribution.get('affiliation') %}
{% if contribution.get('controlledAffiliation') %}
<small class="affiliation-tooltip" data-placement="top"
title="{{ contribution.controlledAffiliation | join(' ; ') }}"><i class="text-muted">{{
contribution.affiliation }}</i></small>
<!-- affiliation -->
{% if contribution.get('affiliation') and contribution.get('controlledAffiliation') %}
<small class="affiliation-tooltip" data-placement="top" title="{{ contribution.controlledAffiliation | join(' ; ') }}">
<i class="text-muted">{{ contribution.affiliation }}</i></small>
{% else %}
<small><i class="text-muted">{{ contribution.affiliation }}</i></small>
{% endif %}
{% endif %}
{% endmacro %}

0 comments on commit 51ad7d5

Please sign in to comment.