From 2f616eec3417a870d97587c2c499018bb8b1c698 Mon Sep 17 00:00:00 2001 From: ducica Date: Mon, 14 Oct 2024 10:01:13 +0200 Subject: [PATCH 1/4] expanding record on detail --- oarepo_ui/resources/config.py | 3 +++ oarepo_ui/resources/resource.py | 21 +++++++++++++------ .../components/IdentifiersAndLinks.jinja | 3 +++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/oarepo_ui/resources/config.py b/oarepo_ui/resources/config.py index a0e207fa..5077acf6 100644 --- a/oarepo_ui/resources/config.py +++ b/oarepo_ui/resources/config.py @@ -92,6 +92,9 @@ class RecordsUIResourceConfig(UIResourceConfig): request_export_args = {"export_format": ma.fields.Str()} request_search_args = {"page": ma.fields.Integer(), "size": ma.fields.Integer()} request_create_args = {"community": ma.fields.Str()} + request_extra_args = { + "expand": ma.fields.Boolean(), + } app_contexts = None ui_serializer = None diff --git a/oarepo_ui/resources/resource.py b/oarepo_ui/resources/resource.py index 3bc6d0f1..3e6164de 100644 --- a/oarepo_ui/resources/resource.py +++ b/oarepo_ui/resources/resource.py @@ -24,6 +24,7 @@ request_read_args, request_search_args, request_view_args, + request_extra_args, ) from invenio_records_resources.services import LinksTemplate from oarepo_runtime.datastreams.utils import get_file_service_for_record_class @@ -60,7 +61,6 @@ class UIComponentsMixin: - # # Pluggable components # @@ -188,6 +188,7 @@ def ui_model(self): # helper function to avoid duplicating code between detail and preview handler @request_read_args @request_view_args + @request_extra_args @response_header_signposting def _detail(self, *, is_preview=False): if is_preview: @@ -260,10 +261,14 @@ def _detail(self, *, is_preview=False): "is_preview": is_preview, } - response = Response(current_oarepo_ui.catalog.render( - render_method, - **render_kwargs, - ), mimetype="text/html", status=200) + response = Response( + current_oarepo_ui.catalog.render( + render_method, + **render_kwargs, + ), + mimetype="text/html", + status=200, + ) response._api_record = api_record return response @@ -316,7 +321,11 @@ def _get_record(self, resource_requestctx, allow_draft=False): else: read_method = self.api_service.read - return read_method(g.identity, resource_requestctx.view_args["pid_value"]) + return read_method( + g.identity, + resource_requestctx.view_args["pid_value"], + expand=resource_requestctx.args.get("expand", False), + ) except PermissionDenied as e: raise Forbidden() from e diff --git a/oarepo_ui/templates/components/IdentifiersAndLinks.jinja b/oarepo_ui/templates/components/IdentifiersAndLinks.jinja index f385d319..c7d20a1f 100644 --- a/oarepo_ui/templates/components/IdentifiersAndLinks.jinja +++ b/oarepo_ui/templates/components/IdentifiersAndLinks.jinja @@ -1,5 +1,6 @@ {# def originalRecordUrl=None, objectIdentifiers=None #} +{% if objectIdentifiers|length > 0 or originalRecordUrl %} +{% endif %} + From 19a7f44f0b204b9ae3115e983ab6c6688aed7879 Mon Sep 17 00:00:00 2001 From: ducica Date: Mon, 14 Oct 2024 10:10:00 +0200 Subject: [PATCH 2/4] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 7cf70da6..a14a51bd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-ui -version = 5.2.14 +version = 5.2.15 description = UI module for invenio 3.5+ long_description = file: README.md long_description_content_type = text/markdown From b257b6768e63cd57c93b750fba9c44b10cf130b8 Mon Sep 17 00:00:00 2001 From: ducica Date: Mon, 14 Oct 2024 10:13:46 +0200 Subject: [PATCH 3/4] always expand the record --- oarepo_ui/resources/config.py | 3 --- oarepo_ui/resources/resource.py | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/oarepo_ui/resources/config.py b/oarepo_ui/resources/config.py index 5077acf6..a0e207fa 100644 --- a/oarepo_ui/resources/config.py +++ b/oarepo_ui/resources/config.py @@ -92,9 +92,6 @@ class RecordsUIResourceConfig(UIResourceConfig): request_export_args = {"export_format": ma.fields.Str()} request_search_args = {"page": ma.fields.Integer(), "size": ma.fields.Integer()} request_create_args = {"community": ma.fields.Str()} - request_extra_args = { - "expand": ma.fields.Boolean(), - } app_contexts = None ui_serializer = None diff --git a/oarepo_ui/resources/resource.py b/oarepo_ui/resources/resource.py index 3e6164de..ece51987 100644 --- a/oarepo_ui/resources/resource.py +++ b/oarepo_ui/resources/resource.py @@ -24,7 +24,6 @@ request_read_args, request_search_args, request_view_args, - request_extra_args, ) from invenio_records_resources.services import LinksTemplate from oarepo_runtime.datastreams.utils import get_file_service_for_record_class @@ -188,7 +187,6 @@ def ui_model(self): # helper function to avoid duplicating code between detail and preview handler @request_read_args @request_view_args - @request_extra_args @response_header_signposting def _detail(self, *, is_preview=False): if is_preview: @@ -324,7 +322,7 @@ def _get_record(self, resource_requestctx, allow_draft=False): return read_method( g.identity, resource_requestctx.view_args["pid_value"], - expand=resource_requestctx.args.get("expand", False), + expand=True, ) except PermissionDenied as e: raise Forbidden() from e From c4c5eae2d877defa8f30bcdf57614f2620f8d2be Mon Sep 17 00:00:00 2001 From: ducica Date: Mon, 14 Oct 2024 10:34:37 +0200 Subject: [PATCH 4/4] fixed test --- tests/test_edit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_edit.py b/tests/test_edit.py index 82e64cfa..2edcc925 100644 --- a/tests/test_edit.py +++ b/tests/test_edit.py @@ -9,10 +9,11 @@ def test_edit( assert json.loads(c.text) == { "api_record": simple_record.id, "data": { + "expanded": {}, "links": { "self": f"https://127.0.0.1:5000/api/simple-model/{simple_record.id}", "ui": f"https://127.0.0.1:5000/simple-model/{simple_record.id}", - } + }, }, "extra_context": { "permissions": {