Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle undefined record attributes in templates to avoid rendering errors #2932

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Copyright (C) 2020 Northwestern University.
Copyright (C) 2021 Graz University of Technology.
Copyright (C) 2021-2022 New York University.
Copyright (C) 2025 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.
Expand All @@ -15,11 +16,11 @@
{% for scheme, details in config.APP_RDM_IDENTIFIER_SCHEMES_UI.items() %}
{% for identifier in creatibutor.person_or_org.identifiers|selectattr("scheme", "equalto", scheme) %}
{% set identifier_found.value = True %}
<a href="{{ identifier.identifier|pid_url(scheme) }}"
aria-label="{{ creatibutor.person_or_org.name }}'s {{ details.label }} {{ _('profile') }}"
<a href="{{ identifier.identifier|pid_url(scheme) }}"
aria-label="{{ creatibutor.person_or_org.name }}'s {{ details.label }} {{ _('profile') }}"
title="{{ creatibutor.person_or_org.name }}'s {{ details.label }} {{ _('profile') }}">
<img class="ml-5 inline-id-icon"
src="{{ url_for('static', filename=details.icon) }}"
<img class="ml-5 inline-id-icon"
src="{{ url_for('static', filename=details.icon) }}"
alt="{{ details.label }} icon"/>
</a>
{% endfor %}
Expand All @@ -39,7 +40,7 @@


{% macro show_creatibutors(creatibutors, show_affiliations=False, type="creators", show_role=False) %}
{% for creatibutor in creatibutors %}
{% for creatibutor in creatibutors if creatibutor.person_or_org and creatibutor.person_or_org.name %}
Copy link
Member Author

@Samk13 Samk13 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While in community review, you can edit a contributor by removing their name but keeping the required role. Upon saving, the reviewer will encounter an error.

<li class="creatibutor-wrap separated">
<a class="ui creatibutor-link"
{% if show_affiliations and creatibutor.affiliations %}
Expand Down Expand Up @@ -85,11 +86,11 @@
{% for affiliation in affiliations %}
<li>
{{ affiliation[0] }}.

{% if affiliation[2] %}
{% set scheme, identifier = (affiliation[2].split(':', 1) if ':' in affiliation[2] else ('ror', affiliation[2])) %}
{% set scheme_config = config.APP_RDM_IDENTIFIER_SCHEMES_UI.get(scheme) %}

{% if scheme_config %}
<a class="no-text-decoration"
href="{{ scheme_config.url_prefix + identifier }}"
Expand All @@ -103,11 +104,11 @@
</a>
{% endif %}
{% endif %}

{{ affiliation[1] }}
</li>
{% endfor %}

</ul>
</section>
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{#
Copyright (C) 2020-2025 CERN.
Copyright (C) 2024 Northwestern University.
Copyright (C) 2024-2025 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.
Expand Down Expand Up @@ -59,18 +60,25 @@

{% macro show_add_descriptions(add_descriptions) %}
{% for add_description in add_descriptions %}
<section id="additional-description-{{ loop.index }}" class="rel-mt-2 rich-input-content"
aria-label="{{ _( add_description.type.title_l10n ) }}">
<h2>{{ add_description.type.title_l10n }} <span
class="text-muted language">{{ '(' + add_description.lang.title_l10n + ')' if add_description.lang }}</span>
{% set desc_type_defined = add_description.type is defined %}
{% set desc_text = add_description.description|default('') %}
<section
id="additional-description-{{ loop.index }}"
class="rel-mt-2 rich-input-content"
aria-label="{{ (add_description.type.title_l10n if desc_type_defined else _('Missing description type!')) }}"
>
<h2>
{{ add_description.type.title_l10n if desc_type_defined else _('Missing description type!') }}
<span class="text-muted language">
{{ '(' ~ add_description.lang.title_l10n ~ ')' if add_description.lang is defined else '' }}
</span>
</h2>

{% if add_description.type.id == "notes" %}
{% if desc_type_defined and add_description.type.id == "notes" %}
<div class="ui message warning">
{{ add_description.description | sanitize_html() | safe }}
{{ desc_text | sanitize_html() | safe }}
</div>
{% else %}
{{ add_description.description | sanitize_html() | safe }}
{{ desc_text | sanitize_html() | safe }}
{% endif %}
</section>
{% endfor %}
Expand All @@ -79,10 +87,11 @@ <h2>{{ add_description.type.title_l10n }} <span

{% macro show_dates(dates) %}
{% for date in dates %}
<dt class="ui tiny header">{{ date.type.title_l10n }}</dt>
{% set date_type_title = date.type.title_l10n if (date.type is defined and date.type.title_l10n is defined) else _('Unknown date type') %}
<dt class="ui tiny header">{{ date_type_title }}</dt>
<dd>
<div>{{ date.date }}</div>
<div class="text-muted">{{ date.description }}</div>
<div>{{ date.date|default('') }}</div>
<div class="text-muted">{{ date.description|default('') }}</div>
</dd>
{% endfor %}
{% endmacro %}
Expand All @@ -103,7 +112,7 @@ <h2>{{ add_description.type.title_l10n }} <span
{% if item.award.acronym %}
{{ item.award.acronym }} –
{% endif %}

{%- if item.award.title_l10n -%}
{{ item.award.title_l10n }}
{%- endif -%}
Expand All @@ -130,15 +139,13 @@ <h2>{{ add_description.type.title_l10n }} <span
{% macro show_references(references) %}
<ul class="ui bulleted list details-list">
{% for reference in references %}
{% set reference_string = reference.reference %}
{% if 'identifier' in reference %}
{% if 'scheme' in reference %}
{% set reference_string = reference.reference|default('') %}
{% if reference.identifier is defined and reference.identifier %}
{% if reference.scheme is defined and reference.scheme %}
{% set reference_scheme = reference.scheme | get_scheme_label %}
{% set reference_string = reference_string + ' ( ' + reference_scheme +
' - ' + reference.identifier + ' )' %}
{% set reference_string = reference_string ~ ' (' ~ reference_scheme ~ ' - ' ~ reference.identifier ~ ')' %}
{% else %}
{% set reference_string = reference_string + ' ( ' + reference.identifier +
' )' %}
{% set reference_string = reference_string ~ ' (' ~ reference.identifier ~ ')' %}
{% endif %}
{% endif %}
<li class="item">{{ reference_string | urlize }}</li>
Expand All @@ -150,28 +157,31 @@ <h2>{{ add_description.type.title_l10n }} <span
{% macro _identifiers_for_group(related_identifiers) %}
{% for identifier in related_identifiers %}
<dd>
{% if identifier.resource_type is defined %}
{% if identifier.resource_type is defined and identifier.resource_type.title_l10n is defined %}
{{ identifier.resource_type.title_l10n }}:
{% endif %}

{% set url = identifier.identifier|pid_url %}
{% set ident_val = identifier.identifier|default('') %}
{% set url = ident_val|pid_url %}
{% if url %}
<a href="{{ url }}" target="_blank" title="{{ _('Opens in new tab') }}">
{{ identifier.identifier }}
{{ ident_val }}
</a>
{% else %}
{{ identifier.identifier }}
{{ ident_val }}
{% endif %}

{{ ' (' + identifier.scheme | get_scheme_label + ')' }}
{% if identifier.scheme is defined and identifier.scheme %}
{{ ' (' ~ (identifier.scheme|get_scheme_label) ~ ')' }}
{% endif %}
</dd>
{% endfor %}
{% endmacro %}


{% macro show_related_identifiers(related_identifiers) %}
<dl class="details-list">
{%- 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') %}
<dt class="ui tiny header">{{ group.grouper }}</dt>
{{ _identifiers_for_group(group.list) }}
{%- endfor %}
Expand Down