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 file-preview #169

Merged
Merged
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
10 changes: 5 additions & 5 deletions invenio_records_lom/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
7 changes: 4 additions & 3 deletions invenio_records_lom/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +26,7 @@
url_prefix = "/oer"


class LOMDraftFilesResourceConfig(FileResourceConfig):
class LOMDraftFilesResourceConfig(FileResourceConfig, ConfiguratorMixin):
"""LOM Draft Files Resource configuration."""

blueprint_name = "lom_draft_files"
Expand All @@ -39,15 +40,15 @@ class LOMDraftFilesResourceConfig(FileResourceConfig):
}


class LOMRecordFilesResourceConfig(FileResourceConfig):
class LOMRecordFilesResourceConfig(FileResourceConfig, ConfiguratorMixin):
"""LOM Record Files Resource configuration."""

allow_upload = False
blueprint_name = "lom_record_files"
url_prefix = f"{url_prefix}/<pid_value>"


class LOMRecordResourceConfig(RecordResourceConfig):
class LOMRecordResourceConfig(RecordResourceConfig, ConfiguratorMixin):
"""LOM Record Resource configuration."""

blueprint_name = "lom_records"
Expand Down
6 changes: 4 additions & 2 deletions invenio_records_lom/ui/records/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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,
*,
Expand All @@ -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):
Expand Down