From 9c971317687327b371608263b8b573a64ce1e91f Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Thu, 5 Dec 2024 02:12:40 +0100 Subject: [PATCH 1/6] fix: improve handling of additional descriptions in detail template * Handle missing 'type' in description rendering * Add the missing description type when the type is not specified. * closes https://github.com/inveniosoftware/invenio-app-rdm/issues/2931 --- .../invenio_app_rdm/records/macros/detail.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html index fd36855a1..7789a358d 100644 --- a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html +++ b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html @@ -1,6 +1,7 @@ {# Copyright (C) 2020-2024 CERN. Copyright (C) 2024 Northwestern University. + Copyright (C) 2024 KTH Royal Institute of Technology. Invenio RDM Records is free software; you can redistribute it and/or modify it under the terms of the MIT License; see LICENSE file for more details. @@ -60,12 +61,14 @@ {% macro show_add_descriptions(add_descriptions) %} {% for add_description in add_descriptions %}
-

{{ add_description.type.title_l10n }} {{ '(' + add_description.lang.title_l10n + ')' if add_description.lang }} + aria-label="{{ _( add_description.type.title_l10n ) if add_description.type is defined else 'Missing description!' }}"> +

{{ add_description.type.title_l10n if add_description.type is defined else _('Missing Additional description type!') }} + + {{ '(' + add_description.lang.title_l10n + ')' if add_description.lang is defined else '' }} +

- {% if add_description.type.id == "notes" %} + {% if add_description.type is defined and add_description.type.id == "notes" %}
{{ add_description.description | sanitize_html() | safe }}
From 95c5d20c440b5d10b0a2b2ac47c6a477696394c2 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Fri, 6 Dec 2024 12:25:21 +0100 Subject: [PATCH 2/6] fix: improve handling for other fields * fix show_dates * fix _identifiers_for_group * fix show_related_identifiers by filtering with selectattr: https://jinja.palletsprojects.com/en/stable/templates/#jinja-filters.selectattr --- .../records/macros/detail.html | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html index 7789a358d..bfe18b40e 100644 --- a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html +++ b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html @@ -60,20 +60,25 @@ {% macro show_add_descriptions(add_descriptions) %} {% for add_description in add_descriptions %} -
-

{{ add_description.type.title_l10n if add_description.type is defined else _('Missing Additional description type!') }} + {% set desc_type_defined = add_description.type is defined %} + {% set desc_text = add_description.description|default('') %} +
+

+ {{ add_description.type.title_l10n if desc_type_defined else _('Missing description type!') }} - {{ '(' + add_description.lang.title_l10n + ')' if add_description.lang is defined else '' }} + {{ '(' ~ add_description.lang.title_l10n ~ ')' if add_description.lang is defined else '' }}

- - {% if add_description.type is defined and add_description.type.id == "notes" %} + {% if desc_type_defined and add_description.type.id == "notes" %}
- {{ add_description.description | sanitize_html() | safe }} + {{ desc_text | sanitize_html() | safe }}
{% else %} - {{ add_description.description | sanitize_html() | safe }} + {{ desc_text | sanitize_html() | safe }} {% endif %}
{% endfor %} @@ -82,7 +87,7 @@

{{ add_description.type.title_l10n if add_description.type is defined else _ {% macro show_dates(dates) %} {% for date in dates %} -
{{ date.type.title_l10n }}
+
{{ date.type.title_l10n if date.type is defined else _('Unknown date type') }}
{{ date.date }}
{{ date.description }}
@@ -160,16 +165,19 @@

{{ add_description.type.title_l10n if add_description.type is defined else _ {{ identifier.resource_type.title_l10n }}: {% endif %} - {% set url = identifier.identifier|pid_url %} + {% set ident_val = identifier.identifier if identifier.identifier is defined else '' %} + {% set url = ident_val|pid_url %} {% if url %} - {{ identifier.identifier }} + {{ ident_val }} {% else %} - {{ identifier.identifier }} + {{ ident_val }} {% endif %} - {{ ' (' + identifier.scheme | get_scheme_label + ')' }} + {% if identifier.scheme is defined %} + {{ ' (' ~ (identifier.scheme|get_scheme_label) ~ ')' }} + {% endif %}

{% endfor %} {% endmacro %} @@ -177,7 +185,7 @@

{{ add_description.type.title_l10n if add_description.type is defined else _ {% macro show_related_identifiers(related_identifiers) %}
- {%- for group in related_identifiers | groupby('relation_type.title_l10n') %} + {%- for group in (related_identifiers|selectattr("relation_type","defined")|list) | groupby('relation_type.title_l10n') %}
{{ group.grouper }}
{{ _identifiers_for_group(group.list) }} {%- endfor %} From 40cb383f6b2ca5512ea99de8856fc77bf3194eb2 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Fri, 6 Dec 2024 12:40:04 +0100 Subject: [PATCH 3/6] fix: enhance date handling in detail template --- .../semantic-ui/invenio_app_rdm/records/macros/detail.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html index bfe18b40e..745a9a28b 100644 --- a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html +++ b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html @@ -87,10 +87,11 @@

{% macro show_dates(dates) %} {% for date in dates %} -
{{ date.type.title_l10n if date.type is defined else _('Unknown date type') }}
+ {% set date_type_title = date.type.title_l10n if (date.type is defined and date.type.title_l10n is defined) else _('Unknown date type') %} +
{{ date_type_title }}
-
{{ date.date }}
-
{{ date.description }}
+
{{ date.date|default('') }}
+
{{ date.description|default('') }}
{% endfor %} {% endmacro %} From e797f19602b1181510eeeb69c0201db13c55d321 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Fri, 6 Dec 2024 12:43:12 +0100 Subject: [PATCH 4/6] fix: improve funding item display logic in detail template --- .../records/macros/detail.html | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html index 745a9a28b..c3eedbda8 100644 --- a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html +++ b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html @@ -105,25 +105,28 @@

{% macro _show_funding_item(item, index) %} - {%- if item.award -%} - {%- if item.award.title_l10n -%} + {% set has_award = item is defined and item.award is defined %} + {% set award_title = item.award.title_l10n if has_award and item.award.title_l10n is defined else '' %} + {% set funder_name = item.funder.name if item.funder is defined and item.funder.name is defined else '' %} + + {% if has_award %} + {% if award_title %}
- {% if item.award.acronym %} + {% if item.award.acronym is defined and item.award.acronym %} {{ item.award.acronym }} – {% endif %} - - {{ item.award.title_l10n }} + {{ award_title }} - {%- if item.award.number -%} + {%- if item.award.number is defined and item.award.number -%} {{ item.award.number }} {%- endif -%} - {%- if item.award.identifiers -%} - {% for identifier in item.award.identifiers if 'url' == identifier.scheme %} + {%- if item.award.identifiers is defined -%} + {% for identifier in item.award.identifiers if identifier.scheme == 'url' %} @@ -132,9 +135,9 @@

{%- endif -%}

{%- endif -%} -
{{ item.funder.name if item.funder }}
+
{{ funder_name }}
{%- else -%} -
{{ item.funder.name if item.funder }}
+
{{ funder_name }}
{%- endif -%} {% endmacro %} From ee7c4657ddf47bd0407a7eb86ff3f5f6df2c099b Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Fri, 6 Dec 2024 12:51:59 +0100 Subject: [PATCH 5/6] fix: enhance show_references macro --- .../invenio_app_rdm/records/macros/detail.html | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html index c3eedbda8..e9f3596de 100644 --- a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html +++ b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/macros/detail.html @@ -145,15 +145,13 @@

{% macro show_references(references) %}