Skip to content

Commit

Permalink
UI marshmallow base RDM schema (#255)
Browse files Browse the repository at this point in the history
* UI marshmallow base RDM schema

* Generated translations

* added translations

---------

Co-authored-by: ducica <[email protected]>
  • Loading branch information
mesemus and Ducica authored Feb 17, 2025
1 parent e071d6c commit f28a7f5
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 19 deletions.
4 changes: 1 addition & 3 deletions oarepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ i18n:
babel_output_translations: oarepo_runtime/translations
babel_source_paths:
- oarepo_runtime/
# hack - make-translations can not handle non-javascript case
i18next_output_translations: /tmp/oarepo-runtime-tmp
languages:
- cs
- en
- en
49 changes: 49 additions & 0 deletions oarepo_runtime/services/schema/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from babel.dates import format_date
from babel_edtf import format_edtf
from flask import current_app
from invenio_rdm_records.records.systemfields.access.field.record import (
AccessStatusEnum,
)
from invenio_rdm_records.resources.serializers.ui.fields import (
UIObjectAccessStatus as InvenioUIObjectAccessStatus,
)
from marshmallow_utils.fields import (
BabelGettextDictField,
FormatDate,
Expand All @@ -15,6 +21,9 @@
from marshmallow_utils.fields.babel import BabelFormatField

from oarepo_runtime.i18n import gettext
from oarepo_runtime.i18n import lazy_gettext as _

from .marshmallow import RDMBaseRecordSchema


def current_default_locale():
Expand Down Expand Up @@ -131,3 +140,43 @@ class InvenioUISchema(ma.Schema):
links = ma.fields.Raw(dump_only=True)
revision_id = ma.fields.Integer(dump_only=True)
expanded = ma.fields.Raw(dump_only=True)


# seems not possible to avoid, as they have this hardcoded in their object,
# and translation keys are i.e. open, which gets translated to otevret
class UIObjectAccessStatus(InvenioUIObjectAccessStatus):
@property
def title(self):
"""Access status title."""
return {
AccessStatusEnum.OPEN: _("access.status.open"),
AccessStatusEnum.EMBARGOED: _("access.status.embargoed"),
AccessStatusEnum.RESTRICTED: _("access.status.restricted"),
AccessStatusEnum.METADATA_ONLY: _("access.status.metadata-only"),
}.get(self.access_status)


class AccessStatusField(ma.fields.Field):
"""Record access status."""

def _serialize(self, value, attr, obj, **kwargs):
"""Serialise access status."""
record_access_dict = obj.get("access")
_files = obj.get("files", {})
has_files = _files is not None and _files.get("enabled", False)
if record_access_dict:
record_access_status_ui = UIObjectAccessStatus(
record_access_dict, has_files
)
return {
"id": record_access_status_ui.id,
"title_l10n": record_access_status_ui.title,
"description_l10n": record_access_status_ui.description,
"icon": record_access_status_ui.icon,
"embargo_date_l10n": record_access_status_ui.embargo_date,
"message_class": record_access_status_ui.message_class,
}


class InvenioRDMUISchema(InvenioUISchema, RDMBaseRecordSchema):
is_draft = ma.fields.Boolean(dump_only=True)
Binary file modified oarepo_runtime/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
16 changes: 16 additions & 0 deletions oarepo_runtime/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,19 @@ msgstr "Ne"
#, python-format
msgid "Invalid value %(identifier)s of identifier type %(type)s"
msgstr "%(type)s: Neplatná hodnota '%(identifier)s'"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:152
msgid "access.status.open"
msgstr "otevřený přístup"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:153
msgid "access.status.embargoed"
msgstr "odložené zpřístupnění"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:154
msgid "access.status.restricted"
msgstr "omezený přístup"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:155
msgid "access.status.metadata-only"
msgstr "pouze metadata"
Binary file modified oarepo_runtime/translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
16 changes: 16 additions & 0 deletions oarepo_runtime/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ msgstr ""
#, python-format
msgid "Invalid value %(identifier)s of identifier type %(type)s"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:152
msgid "access.status.open"
msgstr "open access"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:153
msgid "access.status.embargoed"
msgstr "embargoed access"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:154
msgid "access.status.restricted"
msgstr "restricted access"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:155
msgid "access.status.metadata-only"
msgstr "metadata only access"
48 changes: 32 additions & 16 deletions oarepo_runtime/translations/messages.pot
Original file line number Diff line number Diff line change
@@ -1,56 +1,72 @@
# Translations template for PROJECT.
# Copyright (C) 2024 ORGANIZATION
# Copyright (C) 2025 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-11-28 10:16+0100\n"
"POT-Creation-Date: 2025-02-17 10:27+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.15.0\n"
"Generated-By: Babel 2.17.0\n"

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/search.py:60
#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/search.py:146
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/search.py:71
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/search.py:175
msgid "By Title"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/search.py:64
#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/translations/default_translations.py:5
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/search.py:75
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/translations/default_translations.py:5
msgid "Best match"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/search.py:68
#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/translations/default_translations.py:3
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/search.py:79
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/translations/default_translations.py:3
msgid "Newest"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/search.py:72
#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/translations/default_translations.py:4
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/search.py:83
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/translations/default_translations.py:4
msgid "Oldest"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:123
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/ui.py:132
msgid "True"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/ui.py:123
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/ui.py:132
msgid "False"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/services/schema/validation.py:19
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/ui.py:152
msgid "access.status.open"
msgstr ""

#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/ui.py:153
msgid "access.status.embargoed"
msgstr ""

#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/ui.py:154
msgid "access.status.restricted"
msgstr ""

#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/ui.py:155
msgid "access.status.metadata-only"
msgstr ""

#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/services/schema/validation.py:31
#, python-format
msgid "Invalid value %(identifier)s of identifier type %(type)s"
msgstr ""

#: /Users/m/w/cesnet/oarepo-runtime/oarepo_runtime/translations/default_translations.py:6
#: /home/dusanst/Projects/oarepo-runtime/oarepo_runtime/translations/default_translations.py:6
msgid "Contact"
msgstr ""

0 comments on commit f28a7f5

Please sign in to comment.