diff --git a/invenio_records_lom/ext.py b/invenio_records_lom/ext.py index ae08b4e..b017c58 100644 --- a/invenio_records_lom/ext.py +++ b/invenio_records_lom/ext.py @@ -84,28 +84,28 @@ def init_services(self, app: Flask) -> None: config=None, ) - def init_resources(self, app: Flask) -> None: # noqa: ARG002 + def init_resources(self, app: Flask) -> None: """Initialize resouces.""" self.draft_files_resource = FileResource( - config=LOMDraftFilesResourceConfig, + config=LOMDraftFilesResourceConfig.build(app), service=self.records_service.draft_files, ) # pylint: disable-next=attribute-defined-outside-init self.iiif_resource = IIIFResource( - config=LOMIIIFResourceConfig, + config=LOMIIIFResourceConfig.build(app), service=self.iiif_service, ) # pylint: disable-next=attribute-defined-outside-init self.record_files_resource = FileResource( - config=LOMRecordFilesResourceConfig, + config=LOMRecordFilesResourceConfig.build(app), service=self.records_service.files, ) # pylint: disable-next=attribute-defined-outside-init self.records_resource = LOMRecordResource( - config=LOMRecordResourceConfig, + config=LOMRecordResourceConfig.build(app), service=self.records_service, ) diff --git a/invenio_records_lom/resources/config.py b/invenio_records_lom/resources/config.py index 89f0c62..a58fc99 100644 --- a/invenio_records_lom/resources/config.py +++ b/invenio_records_lom/resources/config.py @@ -13,6 +13,7 @@ from invenio_rdm_records.resources import IIIFResourceConfig from invenio_records_resources.resources import RecordResourceConfig from invenio_records_resources.resources.files import FileResourceConfig +from invenio_records_resources.services.base.config import ConfiguratorMixin from marshmallow import fields from .serializers import LOMToUIJSONSerializer @@ -25,7 +26,7 @@ url_prefix = "/oer" -class LOMDraftFilesResourceConfig(FileResourceConfig): +class LOMDraftFilesResourceConfig(FileResourceConfig, ConfiguratorMixin): """LOM Draft Files Resource configuration.""" blueprint_name = "lom_draft_files" @@ -39,7 +40,7 @@ class LOMDraftFilesResourceConfig(FileResourceConfig): } -class LOMRecordFilesResourceConfig(FileResourceConfig): +class LOMRecordFilesResourceConfig(FileResourceConfig, ConfiguratorMixin): """LOM Record Files Resource configuration.""" allow_upload = False @@ -47,7 +48,7 @@ class LOMRecordFilesResourceConfig(FileResourceConfig): url_prefix = f"{url_prefix}/" -class LOMRecordResourceConfig(RecordResourceConfig): +class LOMRecordResourceConfig(RecordResourceConfig, ConfiguratorMixin): """LOM Record Resource configuration.""" blueprint_name = "lom_records" diff --git a/invenio_records_lom/ui/records/records.py b/invenio_records_lom/ui/records/records.py index b1cd472..d56d89c 100644 --- a/invenio_records_lom/ui/records/records.py +++ b/invenio_records_lom/ui/records/records.py @@ -53,11 +53,13 @@ def __init__( self, file_item: FileItem, record_pid_value: str, + record: RecordItem = None, url: str | None = None, ) -> None: """Create a new PreviewFile.""" self.file = file_item self.data = file_item.data + self.record = record self.size = self.data["size"] self.filename = self.data["key"] self.bucket = self.data["bucket_id"] @@ -164,7 +166,7 @@ def record_export( @pass_file_metadata def record_file_preview( # noqa: ANN201 pid_value: str | None = None, - record: RecordItem | None = None, # noqa: ARG001 + record: RecordItem | None = None, pid_type: str = "recid", # noqa: ARG001 file_metadata: FileItem | None = None, *, @@ -182,7 +184,7 @@ def record_file_preview( # noqa: ANN201 ) # find a suitable previewer - file_obj = PreviewFile(file_metadata, pid_value, url) + file_obj = PreviewFile(file_metadata, pid_value, record, url) previewers = [file_previewer] if file_previewer else None for plugin in current_previewer.iter_previewers(previewers=previewers): if plugin.can_preview(file_obj):