From dd0ba2304aa509371f5e156a4db9b8434ab49f47 Mon Sep 17 00:00:00 2001 From: jrcastro2 Date: Tue, 7 Jun 2022 17:13:30 +0200 Subject: [PATCH] searchapp: update response handler * closes https://github.com/inveniosoftware/invenio-communities/pull/704 * remove hardcoded translations --- invenio_app_rdm/communities_ui/views/communities.py | 6 +++--- .../invenio_app_rdm/records/details/details.html | 5 +++-- .../invenio_app_rdm/records/macros/detail.html | 4 ++-- invenio_app_rdm/records_ui/views/deposits.py | 2 +- invenio_app_rdm/records_ui/views/records.py | 2 +- invenio_app_rdm/requests_ui/views/requests.py | 8 ++++---- .../js/invenio_app_rdm/deposit/RDMDepositForm.js | 10 ++++------ .../js/invenio_app_rdm/user_dashboard/communities.js | 2 +- invenio_app_rdm/users_ui/searchapp.py | 2 +- 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/invenio_app_rdm/communities_ui/views/communities.py b/invenio_app_rdm/communities_ui/views/communities.py index 24e55a863..1f291c5a4 100644 --- a/invenio_app_rdm/communities_ui/views/communities.py +++ b/invenio_app_rdm/communities_ui/views/communities.py @@ -12,8 +12,8 @@ from invenio_communities.views.decorators import pass_community -@pass_community -def communities_detail(pid_value, community): +@pass_community(serialize=True) +def communities_detail(pid_value, community, community_ui): """Community detail page.""" permissions = community.has_permissions_to( ["update", "read", "search_requests", "search_invites"] @@ -22,7 +22,7 @@ def communities_detail(pid_value, community): return render_template( "invenio_communities/details/index.html", - community=community.to_dict(), # TODO: use serializer + community=community_ui, # Pass permissions so we can disable partially UI components # e.g Settings tab permissions=permissions, diff --git a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/details/details.html b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/details/details.html index 9279dae36..fa7c53d1c 100644 --- a/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/details/details.html +++ b/invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/details/details.html @@ -19,6 +19,7 @@ metadata.references %} {% set rights = record.ui.get('rights') %} +{% set funding = record.ui.get('funding') %} {% set active = true %} {% if hasContent %} @@ -172,7 +173,7 @@

{{ _('Additional details') }}

{% set active = false %} {% endif %} - {% if metadata.funding %} + {% if funding %}
{{ _('Additional details') }} hidden="{{ not active }}" >
- {{ show_funding(metadata.funding) }} + {{ show_funding(funding) }}
{% set active = false %} 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 51a84a1fd..69a870b65 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 @@ -85,10 +85,10 @@

{{add_description.type.title_l10n }} {{ '( {% macro _show_funding_item(item, index) %} {%- if item.award -%} - {%- if item.award.title.en -%} + {%- if item.award.title_l10n -%}
- {{ item.award.title.en }} + {{ item.award.title_l10n }} {%- if item.award.number -%} diff --git a/invenio_app_rdm/records_ui/views/deposits.py b/invenio_app_rdm/records_ui/views/deposits.py index 954b0d5a1..da66d0329 100644 --- a/invenio_app_rdm/records_ui/views/deposits.py +++ b/invenio_app_rdm/records_ui/views/deposits.py @@ -318,7 +318,7 @@ def deposit_edit(pid_value, draft=None, draft_files=None): """Edit an existing deposit.""" files_dict = None if draft_files is None else draft_files.to_dict() ui_serializer = UIJSONSerializer() - record = ui_serializer.serialize_object_to_dict(draft.to_dict()) + record = ui_serializer.dump_obj(draft.to_dict()) return render_template( "invenio_app_rdm/records/deposit.html", diff --git a/invenio_app_rdm/records_ui/views/records.py b/invenio_app_rdm/records_ui/views/records.py index d90634af3..9e86e22a1 100644 --- a/invenio_app_rdm/records_ui/views/records.py +++ b/invenio_app_rdm/records_ui/views/records.py @@ -77,7 +77,7 @@ def open(self): def record_detail(pid_value, record, files, is_preview=False): """Record detail page (aka landing page).""" files_dict = None if files is None else files.to_dict() - record_ui = UIJSONSerializer().serialize_object_to_dict(record.to_dict()) + record_ui = UIJSONSerializer().dump_obj(record.to_dict()) is_draft = record_ui["is_draft"] if is_preview and is_draft: try: diff --git a/invenio_app_rdm/requests_ui/views/requests.py b/invenio_app_rdm/requests_ui/views/requests.py index 7e3f4712b..8b8ddb0f2 100644 --- a/invenio_app_rdm/requests_ui/views/requests.py +++ b/invenio_app_rdm/requests_ui/views/requests.py @@ -41,7 +41,7 @@ def _resolve_topic_draft(request): recid = ResolverRegistry.resolve_entity_proxy(request["topic"])._parse_ref_dict_id() try: record = current_rdm_records_service.read_draft(g.identity, recid, expand=True) - record_ui = UIJSONSerializer().serialize_object_to_dict(record.to_dict()) + record_ui = UIJSONSerializer().dump_obj(record.to_dict()) permissions = record.has_permissions_to( [ "edit", @@ -118,8 +118,8 @@ def user_dashboard_request_view(request, **kwargs): @login_required @pass_request(expand=True) -@pass_community -def community_dashboard_request_view(request, community, **kwargs): +@pass_community(serialize=True) +def community_dashboard_request_view(request, community, community_ui, **kwargs): """Community dashboard requests details view.""" request_type = request["type"] @@ -144,7 +144,7 @@ def community_dashboard_request_view(request, community, **kwargs): base_template="invenio_communities/details/base.html", invenio_request=request.to_dict(), record=record, - community=community.to_dict(), + community=community_ui, permissions=permissions, is_preview=True, draft_is_accepted=request_is_accepted, diff --git a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js index 4702d02f9..26c7c4352 100644 --- a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js +++ b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js @@ -280,9 +280,7 @@ export class RDMDepositForm extends Component { searchApi: { axios: { headers: { - // FIXME use for internationalisation - // Accept: "application/vnd.inveniordm.v1+json" - Accept: "application/json", + Accept: "application/vnd.inveniordm.v1+json", }, url: "/api/awards", withCredentials: false, @@ -300,8 +298,7 @@ export class RDMDepositForm extends Component { labelIcon="money bill alternate outline" deserializeAward={(award) => { return { - title: award.title.en ?? award.title, - pid: award.pid, + title: award.title_l10n, number: award.number, funder: award.funder ?? "", id: award.id, @@ -315,6 +312,7 @@ export class RDMDepositForm extends Component { return { id: funder.id, name: funder.name, + ...(funder.title_l10n && { title: funder.title_l10n }), ...(funder.pid && { pid: funder.pid }), ...(funder.country && { country: funder.country }), ...(funder.identifiers && { @@ -330,7 +328,7 @@ export class RDMDepositForm extends Component { if (funding.funder) { const funderName = funding.funder?.name ?? - funding.funder?.title?.en ?? + funding.funder?.title ?? funding.funder?.id ?? ""; awardOrFunder = "funder"; diff --git a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/user_dashboard/communities.js b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/user_dashboard/communities.js index 32df21748..5a0c771f7 100644 --- a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/user_dashboard/communities.js +++ b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/user_dashboard/communities.js @@ -52,7 +52,7 @@ function ResultsGridItemTemplate({ result, index }) { export function CommunitiesResultsItemTemplate({ result, index }) { const community_type = _get( result, - "metadata.type.title.en", + "ui.type.title_l10n", i18next.t("No community type") ); return ( diff --git a/invenio_app_rdm/users_ui/searchapp.py b/invenio_app_rdm/users_ui/searchapp.py index 9208bc07a..b94ddfb29 100644 --- a/invenio_app_rdm/users_ui/searchapp.py +++ b/invenio_app_rdm/users_ui/searchapp.py @@ -30,7 +30,7 @@ def search_app_context(): current_app.config["COMMUNITIES_FACETS"], current_app.config["RDM_SORT_OPTIONS"], "/api/user/communities", - {"Accept": "application/json"}, + {"Accept": "application/vnd.inveniordm.v1+json"}, ), "search_app_rdm_user_requests_config": partial( search_app_config,