Skip to content

Commit

Permalink
searchapp: update response handler
Browse files Browse the repository at this point in the history
* closes inveniosoftware/invenio-communities#704
* remove hardcoded translations
  • Loading branch information
jrcastro2 authored and zzacharo committed Jun 22, 2022
1 parent 1ab6eef commit dd0ba23
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions invenio_app_rdm/communities_ui/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
metadata.references
%}
{% set rights = record.ui.get('rights') %}
{% set funding = record.ui.get('funding') %}
{% set active = true %}

{% if hasContent %}
Expand Down Expand Up @@ -172,7 +173,7 @@ <h2 id="record-details-heading">{{ _('Additional details') }}</h2>
{% set active = false %}
{% endif %}

{% if metadata.funding %}
{% if funding %}
<div
role="tabpanel"
class="ui bottom attached {{ 'active' if active }} tab segment"
Expand All @@ -182,7 +183,7 @@ <h2 id="record-details-heading">{{ _('Additional details') }}</h2>
hidden="{{ not active }}"
>
<dl class="details-list">
{{ show_funding(metadata.funding) }}
{{ show_funding(funding) }}
</dl>
</div>
{% set active = false %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ <h2>{{add_description.type.title_l10n }} <span class="text-muted language">{{ '(

{% macro _show_funding_item(item, index) %}
{%- if item.award -%}
{%- if item.award.title.en -%}
{%- if item.award.title_l10n -%}
<dt class="ui tiny header">
<span class="mr-5">
{{ item.award.title.en }}
{{ item.award.title_l10n }}
</span>

{%- if item.award.number -%}
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_rdm/records_ui/views/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions invenio_app_rdm/requests_ui/views/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"]

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 && {
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_rdm/users_ui/searchapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dd0ba23

Please sign in to comment.