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 rero#744.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Jul 28, 2022
1 parent 98d08b7 commit 7fde22f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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) }}
</li>
{% endfor %}
</ul>
Expand Down
35 changes: 23 additions & 12 deletions sonar/modules/documents/views.py
Original file line number Diff line number Diff line change
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(meeting)

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


@blueprint.app_template_filter()
def meeting_text(contribution):
"""Display meeting format.
:param contribution: Dict representing the contribution.
:returns: Formatted text.
"""
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:
return '({meeting})'.format(meeting=' : '.join(meeting))


@blueprint.app_template_filter()
def get_custom_field_label(record, custom_field_index):
"""Get the label of a custom field.
Expand Down
19 changes: 14 additions & 5 deletions sonar/theme/templates/sonar/macros/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,27 @@
{% endmacro %}

{% macro contributors_format(contribution) %}
{{ contribution | contribution_text }}
<!-- 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' %}
{{ contribution | meeting_text }}
{% 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') %}
<!-- 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 7fde22f

Please sign in to comment.