oarepo-runtime 1.5.33__py3-none-any.whl → 1.5.34__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- oarepo_runtime/i18n/__init__.py +1 -8
- oarepo_runtime/records/entity_resolvers/__init__.py +4 -88
- oarepo_runtime/records/entity_resolvers/proxies.py +34 -10
- oarepo_runtime/services/schema/i18n.py +13 -10
- oarepo_runtime/services/schema/i18n_ui.py +20 -18
- {oarepo_runtime-1.5.33.dist-info → oarepo_runtime-1.5.34.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.33.dist-info → oarepo_runtime-1.5.34.dist-info}/RECORD +11 -11
- {oarepo_runtime-1.5.33.dist-info → oarepo_runtime-1.5.34.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.33.dist-info → oarepo_runtime-1.5.34.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.33.dist-info → oarepo_runtime-1.5.34.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.33.dist-info → oarepo_runtime-1.5.34.dist-info}/top_level.txt +0 -0
oarepo_runtime/i18n/__init__.py
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
# compatibility setting between invenio rdm 11 and invenio rdm 12
|
4
|
-
# can be removed when invenio rdm 11 is no longer supported
|
5
|
-
if oarepo_version.split(".")[0] == "11":
|
6
|
-
from flask_babelex import get_locale, gettext, lazy_gettext
|
7
|
-
else:
|
8
|
-
from flask_babel import get_locale, gettext, lazy_gettext
|
1
|
+
from flask_babel import get_locale, gettext, lazy_gettext
|
9
2
|
|
10
3
|
__all__ = ("gettext", "lazy_gettext", "get_locale")
|
@@ -1,90 +1,6 @@
|
|
1
|
-
from
|
1
|
+
from oarepo_runtime.records.entity_resolvers.proxies import DraftProxy, RecordProxy
|
2
2
|
|
3
|
-
from
|
3
|
+
from invenio_records_resources.references import EntityResolver, RecordResolver
|
4
|
+
from invenio_users_resources.entity_resolvers import UserResolver, GroupResolver
|
4
5
|
|
5
|
-
|
6
|
-
# can be removed when invenio rdm 11 is no longer supported
|
7
|
-
if oarepo_version.split(".")[0] == "11":
|
8
|
-
from invenio_records_resources.references import EntityResolver, RecordResolver
|
9
|
-
from invenio_users_resources.resolvers import UserResolver
|
10
|
-
|
11
|
-
#copyied from newer invenio_users_resources, GroupResolver isn't in older versions
|
12
|
-
from flask_principal import RoleNeed
|
13
|
-
from invenio_accounts.models import Role
|
14
|
-
from invenio_records_resources.references.resolvers import (
|
15
|
-
EntityProxy,
|
16
|
-
EntityResolver,
|
17
|
-
)
|
18
|
-
from invenio_users_resources.services.groups.config import GroupsServiceConfig
|
19
|
-
from sqlalchemy.exc import NoResultFound
|
20
|
-
|
21
|
-
class GroupProxy(EntityProxy):
|
22
|
-
"""Resolver proxy for a Role entity."""
|
23
|
-
|
24
|
-
def _resolve(self):
|
25
|
-
"""Resolve the User from the proxy's reference dict, or system_identity."""
|
26
|
-
# Resolves to role name, not id
|
27
|
-
role_id = self._parse_ref_dict_id()
|
28
|
-
try:
|
29
|
-
return Role.query.filter(
|
30
|
-
Role.name == role_id # TODO to be changed to role id
|
31
|
-
).one()
|
32
|
-
except NoResultFound:
|
33
|
-
return {}
|
34
|
-
|
35
|
-
def pick_resolved_fields(self, identity, resolved_dict):
|
36
|
-
"""Select which fields to return when resolving the reference."""
|
37
|
-
serialized_role = {}
|
38
|
-
|
39
|
-
return serialized_role
|
40
|
-
|
41
|
-
def get_needs(self, ctx=None):
|
42
|
-
"""Return needs based on the given roles."""
|
43
|
-
role_id = self._parse_ref_dict_id()
|
44
|
-
return [RoleNeed(role_id)]
|
45
|
-
|
46
|
-
def ghost_record(self, value):
|
47
|
-
"""Return default representation of not resolved group.
|
48
|
-
|
49
|
-
.. note::
|
50
|
-
|
51
|
-
Only groups that are not indexed should need this. Non-indexed groups include groups that were not created by users
|
52
|
-
e.g. user-moderation.
|
53
|
-
"""
|
54
|
-
return {}
|
55
|
-
|
56
|
-
|
57
|
-
class GroupResolver(EntityResolver):
|
58
|
-
"""Group entity resolver."""
|
59
|
-
|
60
|
-
type_id = "group"
|
61
|
-
"""Type identifier for this resolver."""
|
62
|
-
|
63
|
-
def __init__(self):
|
64
|
-
"""Constructor."""
|
65
|
-
# There's a bit of a mixup of type_key and type_id. Base resolver has no
|
66
|
-
# type_key, but RecordResolvers have.
|
67
|
-
self.type_key = self.type_id
|
68
|
-
super().__init__(GroupsServiceConfig.service_id)
|
69
|
-
|
70
|
-
def matches_reference_dict(self, ref_dict):
|
71
|
-
"""Check if the reference dict references a role."""
|
72
|
-
return self._parse_ref_dict_type(ref_dict) == self.type_id
|
73
|
-
|
74
|
-
def _reference_entity(self, entity):
|
75
|
-
"""Create a reference dict for the given user."""
|
76
|
-
return {"group": str(entity.id)}
|
77
|
-
|
78
|
-
def matches_entity(self, entity):
|
79
|
-
"""Check if the entity is a Role."""
|
80
|
-
return isinstance(entity, Role)
|
81
|
-
|
82
|
-
def _get_entity_proxy(self, ref_dict):
|
83
|
-
"""Return a GroupProxy for the given reference dict."""
|
84
|
-
return GroupProxy(self, ref_dict)
|
85
|
-
|
86
|
-
else:
|
87
|
-
from invenio_records_resources.references import EntityResolver, RecordResolver
|
88
|
-
from invenio_users_resources.entity_resolvers import UserResolver, GroupResolver
|
89
|
-
|
90
|
-
__all__ = ["DraftProxy", "UserResolver", "GroupResolver", "RecordResolver", "EntityResolver"]
|
6
|
+
__all__ = ["DraftProxy", "UserResolver", "GroupResolver", "RecordResolver", "EntityResolver", "RecordProxy"]
|
@@ -1,22 +1,46 @@
|
|
1
1
|
from invenio_pidstore.errors import PIDUnregistered
|
2
|
-
from oarepo import __version__ as oarepo_version
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
from invenio_records_resources.references.resolvers.records import RecordProxy
|
8
|
-
else:
|
9
|
-
from invenio_records_resources.references.entity_resolvers.records import (
|
10
|
-
RecordProxy,
|
11
|
-
)
|
3
|
+
from invenio_records_resources.references.entity_resolvers.records import (
|
4
|
+
RecordProxy as InvenioRecordProxy,
|
5
|
+
)
|
12
6
|
|
13
7
|
from sqlalchemy.exc import NoResultFound
|
14
8
|
|
15
9
|
|
10
|
+
def set_field(result, resolved_dict, field_name):
|
11
|
+
from_metadata = resolved_dict.get("metadata", {}).get(field_name)
|
12
|
+
from_data = resolved_dict.get(field_name)
|
13
|
+
|
14
|
+
if from_metadata:
|
15
|
+
result.setdefault("metadata", {})[field_name] = from_metadata
|
16
|
+
if from_data:
|
17
|
+
result[field_name] = from_data
|
18
|
+
|
19
|
+
|
20
|
+
class RecordProxy(InvenioRecordProxy):
|
21
|
+
picked_fields = ["title", "creators", "contributors"]
|
22
|
+
|
23
|
+
def pick_resolved_fields(self, identity, resolved_dict):
|
24
|
+
"""Select which fields to return when resolving the reference."""
|
25
|
+
resolved_fields = super().pick_resolved_fields(identity, resolved_dict)
|
26
|
+
|
27
|
+
for fld in self.picked_fields:
|
28
|
+
set_field(resolved_fields, resolved_dict, fld)
|
29
|
+
|
30
|
+
return resolved_fields
|
31
|
+
|
32
|
+
def ghost_record(self, value):
|
33
|
+
return {
|
34
|
+
**value,
|
35
|
+
"metadata": {
|
36
|
+
"title": "Deleted record",
|
37
|
+
},
|
38
|
+
}
|
39
|
+
|
40
|
+
|
16
41
|
class DraftProxy(RecordProxy):
|
17
42
|
def _resolve(self):
|
18
43
|
pid_value = self._parse_ref_dict_id()
|
19
|
-
|
20
44
|
try:
|
21
45
|
return self.record_cls.pid.resolve(pid_value, registered_only=False)
|
22
46
|
except (PIDUnregistered, NoResultFound):
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from functools import lru_cache
|
2
|
-
|
2
|
+
import importlib
|
3
3
|
import langcodes
|
4
|
+
from invenio_base.utils import obj_or_import_string
|
4
5
|
from marshmallow import Schema, ValidationError, fields, validates
|
5
6
|
|
6
7
|
"""
|
@@ -10,39 +11,41 @@ it for each project.
|
|
10
11
|
|
11
12
|
|
12
13
|
@lru_cache
|
13
|
-
def get_i18n_schema(
|
14
|
-
@validates(
|
14
|
+
def get_i18n_schema(lang_name, value_name, value_field="marshmallow_utils.fields.SanitizedHTML"):
|
15
|
+
@validates(lang_name)
|
15
16
|
def validate_lang(self, value):
|
16
17
|
if value != "_" and not langcodes.Language.get(value).is_valid():
|
17
18
|
raise ValidationError("Invalid language code")
|
18
19
|
|
20
|
+
value_field_class = obj_or_import_string(value_field)
|
21
|
+
|
19
22
|
return type(
|
20
|
-
f"I18nSchema_{
|
23
|
+
f"I18nSchema_{lang_name}_{value_name}",
|
21
24
|
(Schema,),
|
22
25
|
{
|
23
26
|
"validate_lang": validate_lang,
|
24
|
-
|
25
|
-
|
27
|
+
lang_name: fields.String(required=True),
|
28
|
+
value_name: value_field_class(required=True),
|
26
29
|
},
|
27
30
|
)
|
28
31
|
|
29
32
|
|
30
33
|
def MultilingualField( # noqa NOSONAR
|
31
|
-
*args,
|
34
|
+
*args, lang_name="lang", value_name="value", value_field="marshmallow_utils.fields.SanitizedHTML", **kwargs
|
32
35
|
):
|
33
36
|
# TODO: args are not used but oarepo-model-builder-multilingual generates them
|
34
37
|
# should be fixed there and subsequently removed here
|
35
38
|
return fields.List(
|
36
|
-
fields.Nested(get_i18n_schema(
|
39
|
+
fields.Nested(get_i18n_schema(lang_name, value_name, value_field)),
|
37
40
|
**kwargs,
|
38
41
|
)
|
39
42
|
|
40
43
|
|
41
44
|
def I18nStrField( # noqa NOSONAR
|
42
|
-
*args,
|
45
|
+
*args, lang_name="lang", value_name="value", value_field="marshmallow_utils.fields.SanitizedHTML", **kwargs
|
43
46
|
):
|
44
47
|
return fields.Nested(
|
45
|
-
get_i18n_schema(
|
48
|
+
get_i18n_schema(lang_name, value_name, value_field),
|
46
49
|
*args,
|
47
50
|
**kwargs,
|
48
51
|
)
|
@@ -1,72 +1,74 @@
|
|
1
1
|
from functools import lru_cache
|
2
2
|
|
3
3
|
from marshmallow import Schema, fields
|
4
|
-
|
4
|
+
from marshmallow_utils.fields import SanitizedHTML
|
5
|
+
from invenio_base.utils import obj_or_import_string
|
5
6
|
|
6
7
|
@lru_cache
|
7
|
-
def get_i18n_ui_schema(
|
8
|
+
def get_i18n_ui_schema(lang_name, value_name, value_field="marshmallow_utils.fields.SanitizedHTML"):
|
9
|
+
value_field_class = obj_or_import_string(value_field)
|
8
10
|
return type(
|
9
|
-
f"I18nUISchema_{
|
11
|
+
f"I18nUISchema_{lang_name}_{value_name}",
|
10
12
|
(Schema,),
|
11
13
|
{
|
12
|
-
|
13
|
-
|
14
|
+
lang_name: fields.String(required=True),
|
15
|
+
value_name: value_field_class(required=True),
|
14
16
|
},
|
15
17
|
)
|
16
18
|
|
17
19
|
|
18
20
|
def MultilingualUIField( # noqa NOSONAR
|
19
|
-
*args,
|
21
|
+
*args, lang_name="lang", value_name="value", value_field="marshmallow_utils.fields.SanitizedHTML", **kwargs
|
20
22
|
):
|
21
23
|
return fields.List(
|
22
|
-
fields.Nested(get_i18n_ui_schema(
|
24
|
+
fields.Nested(get_i18n_ui_schema(lang_name, value_name, value_field)),
|
23
25
|
**kwargs,
|
24
26
|
)
|
25
27
|
|
26
28
|
|
27
29
|
def I18nStrUIField( # noqa NOSONAR
|
28
|
-
*args,
|
30
|
+
*args, lang_name="lang", value_name="value", value_field="marshmallow_utils.fields.SanitizedHTML", **kwargs
|
29
31
|
):
|
30
32
|
return fields.Nested(
|
31
|
-
get_i18n_ui_schema(
|
33
|
+
get_i18n_ui_schema(lang_name, value_name, value_field),
|
32
34
|
*args,
|
33
35
|
**kwargs,
|
34
36
|
)
|
35
37
|
|
36
38
|
|
37
39
|
@lru_cache
|
38
|
-
def get_i18n_localized_ui_schema(
|
40
|
+
def get_i18n_localized_ui_schema(lang_name, value_name):
|
39
41
|
class I18nLocalizedUISchema(Schema):
|
40
42
|
def _serialize(self, value, attr=None, obj=None, **kwargs):
|
41
43
|
if not value:
|
42
44
|
return None
|
43
45
|
language = self.context["locale"].language
|
44
46
|
for v in value:
|
45
|
-
if language == v[
|
46
|
-
return v[
|
47
|
-
return next(iter(value))[
|
47
|
+
if language == v[lang_name]:
|
48
|
+
return v[value_name]
|
49
|
+
return next(iter(value))[value_name]
|
48
50
|
|
49
51
|
# inherit to get a nice name for debugging
|
50
52
|
return type(
|
51
|
-
f"I18nLocalizedUISchema_{
|
53
|
+
f"I18nLocalizedUISchema_{lang_name}_{value_name}",
|
52
54
|
(I18nLocalizedUISchema,),
|
53
55
|
{},
|
54
56
|
)
|
55
57
|
|
56
58
|
|
57
59
|
def MultilingualLocalizedUIField( # noqa NOSONAR
|
58
|
-
*args,
|
60
|
+
*args, lang_name="lang", value_name="value", **kwargs
|
59
61
|
):
|
60
62
|
return fields.Nested(
|
61
|
-
get_i18n_localized_ui_schema(
|
63
|
+
get_i18n_localized_ui_schema(lang_name, value_name), **kwargs
|
62
64
|
)
|
63
65
|
|
64
66
|
|
65
67
|
def I18nStrLocalizedUIField( # noqa NOSONAR
|
66
|
-
*args,
|
68
|
+
*args, lang_name="lang", value_name="value", **kwargs
|
67
69
|
):
|
68
70
|
return fields.Nested(
|
69
|
-
get_i18n_ui_schema(
|
71
|
+
get_i18n_ui_schema(lang_name, value_name),
|
70
72
|
*args,
|
71
73
|
**kwargs,
|
72
74
|
)
|
@@ -39,15 +39,15 @@ oarepo_runtime/datastreams/writers/service.py,sha256=PvCxYASDxOqT6iyL6cjw0aH41La
|
|
39
39
|
oarepo_runtime/datastreams/writers/utils.py,sha256=Lk_ZLNeXTLuFEn04lw1-6bJ7duG6kwA8X4wf9c_GiL4,1067
|
40
40
|
oarepo_runtime/datastreams/writers/validation_errors.py,sha256=wOCXdniR6so_4ExpdFYYgBRyENp7_6kVFZM2L-Hy3G8,661
|
41
41
|
oarepo_runtime/datastreams/writers/yaml.py,sha256=XchUJHQ58E2Mfgs8elImXbL38jFtI8Hfoye6yaR0gKI,1482
|
42
|
-
oarepo_runtime/i18n/__init__.py,sha256=
|
42
|
+
oarepo_runtime/i18n/__init__.py,sha256=h0knW_HwiyIt5TBHfdGqN7_BBYfpz1Fw6zhVy0C28fM,111
|
43
43
|
oarepo_runtime/info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
44
|
oarepo_runtime/info/views.py,sha256=jtI2JJBdApuT5ZIxU2kskJBz6GpJVTgUGrM8EMNIiAk,11137
|
45
45
|
oarepo_runtime/records/__init__.py,sha256=w1vtMmGDpcn9PQ2gbwihrYBZhawhzDWWOpnDdeaOPVo,1038
|
46
46
|
oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
|
47
47
|
oarepo_runtime/records/dumpers/edtf_interval.py,sha256=YCShZAoqBQYaxVilEVotS-jXZsxxoXO67yu2urhkaMA,1198
|
48
48
|
oarepo_runtime/records/dumpers/multilingual_dumper.py,sha256=PbNFCLsiH4XV3E1v8xga_fzlcEImHy8OXn_UKh_8VBU,1090
|
49
|
-
oarepo_runtime/records/entity_resolvers/__init__.py,sha256=
|
50
|
-
oarepo_runtime/records/entity_resolvers/proxies.py,sha256=
|
49
|
+
oarepo_runtime/records/entity_resolvers/__init__.py,sha256=fZFUh53idLswFIlF-5miLPQXMlDX6YEHAolJGgxgh6k,356
|
50
|
+
oarepo_runtime/records/entity_resolvers/proxies.py,sha256=dhWYIjjWzXdoAooHvGeT2PHlfuvFHPSw_839TMXW8jA,1518
|
51
51
|
oarepo_runtime/records/owners/__init__.py,sha256=R4hudCBqLRRzgCnkEjXIL7hSp068z-s6YOwYSkWyuaw,93
|
52
52
|
oarepo_runtime/records/owners/registry.py,sha256=fYgBuW5nBKn6pyz2OBgfNlynk64_yhQ9J7FzPk8QU1U,795
|
53
53
|
oarepo_runtime/records/relations/__init__.py,sha256=bDAgxl_LdKsqpGG3qluxAkQnn5u2ItJngnHQKkqzlkE,373
|
@@ -96,8 +96,8 @@ oarepo_runtime/services/relations/errors.py,sha256=VtlOKq9MEUeJ4IsiZhY7lWoshrusA
|
|
96
96
|
oarepo_runtime/services/relations/mapping.py,sha256=D7IYk83SXVgTv-0ohSnHOCzvCwbFLXJsayO1eQfQn0U,1285
|
97
97
|
oarepo_runtime/services/schema/__init__.py,sha256=gD0II1Lz6fnW1Cgt4gtneZeyKWl_YZ47Wu0gmeKqtH8,1395
|
98
98
|
oarepo_runtime/services/schema/cf.py,sha256=-m9seIH5VYUdxDsJlPVXS0-8f7xkpN7YfW1q9E1GacI,475
|
99
|
-
oarepo_runtime/services/schema/i18n.py,sha256=
|
100
|
-
oarepo_runtime/services/schema/i18n_ui.py,sha256=
|
99
|
+
oarepo_runtime/services/schema/i18n.py,sha256=rCO8hZqRA_653uLn7eobJIsibbjgSLO9Q9Ka-2RG5r0,1645
|
100
|
+
oarepo_runtime/services/schema/i18n_ui.py,sha256=D3YGKToB3MZVqGyiPf_xWPtg9PhGUuOZ5VNfm7fwf68,2203
|
101
101
|
oarepo_runtime/services/schema/i18n_validation.py,sha256=fyMTi2Rw-KiHv7c7HN61zGxRVa9sAjAEEkAL5wUyKNo,236
|
102
102
|
oarepo_runtime/services/schema/marshmallow.py,sha256=LmcSxvbZ9jIhkNHCqqxt1SA2UNijoDmIzqli1MkoTrE,1153
|
103
103
|
oarepo_runtime/services/schema/oneofschema.py,sha256=X_pXzrkYcLGGAtGN1qltrz45OzD_atrJHkHkp3L01xg,6660
|
@@ -115,9 +115,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
115
115
|
oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
|
116
116
|
oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
|
117
117
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
118
|
-
oarepo_runtime-1.5.
|
119
|
-
oarepo_runtime-1.5.
|
120
|
-
oarepo_runtime-1.5.
|
121
|
-
oarepo_runtime-1.5.
|
122
|
-
oarepo_runtime-1.5.
|
123
|
-
oarepo_runtime-1.5.
|
118
|
+
oarepo_runtime-1.5.34.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
119
|
+
oarepo_runtime-1.5.34.dist-info/METADATA,sha256=0JbXNMjCdPlCOSa9qn7U5nJm2k2JF6tOG3CRo6hnYtU,4680
|
120
|
+
oarepo_runtime-1.5.34.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
121
|
+
oarepo_runtime-1.5.34.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
|
122
|
+
oarepo_runtime-1.5.34.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
123
|
+
oarepo_runtime-1.5.34.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|