oarepo-runtime 1.5.33__tar.gz → 1.5.35__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. {oarepo_runtime-1.5.33/oarepo_runtime.egg-info → oarepo_runtime-1.5.35}/PKG-INFO +1 -1
  2. oarepo_runtime-1.5.35/oarepo_runtime/i18n/__init__.py +3 -0
  3. oarepo_runtime-1.5.35/oarepo_runtime/records/entity_resolvers/__init__.py +6 -0
  4. oarepo_runtime-1.5.35/oarepo_runtime/records/entity_resolvers/proxies.py +48 -0
  5. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/results.py +22 -0
  6. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/i18n.py +13 -10
  7. oarepo_runtime-1.5.35/oarepo_runtime/services/schema/i18n_ui.py +74 -0
  8. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35/oarepo_runtime.egg-info}/PKG-INFO +1 -1
  9. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/setup.cfg +2 -2
  10. oarepo_runtime-1.5.33/oarepo_runtime/i18n/__init__.py +0 -10
  11. oarepo_runtime-1.5.33/oarepo_runtime/records/entity_resolvers/__init__.py +0 -90
  12. oarepo_runtime-1.5.33/oarepo_runtime/records/entity_resolvers/proxies.py +0 -24
  13. oarepo_runtime-1.5.33/oarepo_runtime/services/schema/i18n_ui.py +0 -72
  14. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/LICENSE +0 -0
  15. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/MANIFEST.in +0 -0
  16. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/README.md +0 -0
  17. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/__init__.py +0 -0
  18. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/__init__.py +0 -0
  19. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/assets.py +0 -0
  20. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/base.py +0 -0
  21. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/cf.py +0 -0
  22. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/check.py +0 -0
  23. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/configuration.py +0 -0
  24. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/fixtures.py +0 -0
  25. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/index.py +0 -0
  26. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/cli/validate.py +0 -0
  27. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/__init__.py +0 -0
  28. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/asynchronous.py +0 -0
  29. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/catalogue.py +0 -0
  30. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/datastreams.py +0 -0
  31. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/errors.py +0 -0
  32. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/ext.py +0 -0
  33. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/fixtures.py +0 -0
  34. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/json.py +0 -0
  35. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/readers/__init__.py +0 -0
  36. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/readers/attachments.py +0 -0
  37. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/readers/excel.py +0 -0
  38. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/readers/json.py +0 -0
  39. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/readers/service.py +0 -0
  40. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/readers/yaml.py +0 -0
  41. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/semi_asynchronous.py +0 -0
  42. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/synchronous.py +0 -0
  43. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/transformers.py +0 -0
  44. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/types.py +0 -0
  45. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/utils.py +0 -0
  46. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/__init__.py +0 -0
  47. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/attachments_file.py +0 -0
  48. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/attachments_service.py +0 -0
  49. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/service.py +0 -0
  50. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/utils.py +0 -0
  51. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/validation_errors.py +0 -0
  52. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/datastreams/writers/yaml.py +0 -0
  53. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/ext.py +0 -0
  54. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/ext_config.py +0 -0
  55. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/info/__init__.py +0 -0
  56. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/info/views.py +0 -0
  57. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/profile.py +0 -0
  58. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/proxies.py +0 -0
  59. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/__init__.py +0 -0
  60. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/dumpers/__init__.py +0 -0
  61. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/dumpers/edtf_interval.py +0 -0
  62. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/dumpers/multilingual_dumper.py +0 -0
  63. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/owners/__init__.py +0 -0
  64. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/owners/registry.py +0 -0
  65. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/relations/__init__.py +0 -0
  66. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/relations/base.py +0 -0
  67. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/relations/internal.py +0 -0
  68. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/relations/lookup.py +0 -0
  69. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/relations/pid_relation.py +0 -0
  70. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/__init__.py +0 -0
  71. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/featured_file.py +0 -0
  72. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/has_draftcheck.py +0 -0
  73. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/icu.py +0 -0
  74. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/mapping.py +0 -0
  75. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/owner.py +0 -0
  76. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/record_status.py +0 -0
  77. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/selectors.py +0 -0
  78. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/records/systemfields/synthetic.py +0 -0
  79. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/resources/__init__.py +0 -0
  80. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/resources/file_resource.py +0 -0
  81. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/resources/localized_ui_json_serializer.py +0 -0
  82. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/__init__.py +0 -0
  83. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/components.py +0 -0
  84. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/config/__init__.py +0 -0
  85. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/config/permissions_presets.py +0 -0
  86. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/config/service.py +0 -0
  87. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/custom_fields/__init__.py +0 -0
  88. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/custom_fields/mappings.py +0 -0
  89. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/expansions/__init__.py +0 -0
  90. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/expansions/expandable_fields.py +0 -0
  91. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/expansions/service.py +0 -0
  92. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/__init__.py +0 -0
  93. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/base.py +0 -0
  94. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/date.py +0 -0
  95. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/enum.py +0 -0
  96. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/facet_groups_names.py +0 -0
  97. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/max_facet.py +0 -0
  98. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/nested_facet.py +0 -0
  99. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/facets/params.py +0 -0
  100. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/files/__init__.py +0 -0
  101. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/files/service.py +0 -0
  102. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/generators.py +0 -0
  103. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/relations/__init__.py +0 -0
  104. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/relations/components.py +0 -0
  105. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/relations/errors.py +0 -0
  106. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/relations/mapping.py +0 -0
  107. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/__init__.py +0 -0
  108. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/cf.py +0 -0
  109. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/i18n_validation.py +0 -0
  110. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/marshmallow.py +0 -0
  111. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/oneofschema.py +0 -0
  112. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/polymorphic.py +0 -0
  113. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/ui.py +0 -0
  114. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/schema/validation.py +0 -0
  115. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/services/search.py +0 -0
  116. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/cs/LC_MESSAGES/messages.mo +0 -0
  117. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/cs/LC_MESSAGES/messages.po +0 -0
  118. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/default_translations.py +0 -0
  119. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/en/LC_MESSAGES/messages.mo +0 -0
  120. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/en/LC_MESSAGES/messages.po +0 -0
  121. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/jinjax_messages.jinja +0 -0
  122. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/translations/messages.pot +0 -0
  123. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/uow.py +0 -0
  124. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/utils/__init__.py +0 -0
  125. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/utils/functools.py +0 -0
  126. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime/utils/path.py +0 -0
  127. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime.egg-info/SOURCES.txt +0 -0
  128. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime.egg-info/dependency_links.txt +0 -0
  129. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime.egg-info/entry_points.txt +0 -0
  130. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime.egg-info/requires.txt +0 -0
  131. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/oarepo_runtime.egg-info/top_level.txt +0 -0
  132. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/pyproject.toml +0 -0
  133. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/setup.py +0 -0
  134. {oarepo_runtime-1.5.33 → oarepo_runtime-1.5.35}/tests/pkg_data/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.33
3
+ Version: 1.5.35
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -0,0 +1,3 @@
1
+ from flask_babel import get_locale, gettext, lazy_gettext
2
+
3
+ __all__ = ("gettext", "lazy_gettext", "get_locale")
@@ -0,0 +1,6 @@
1
+ from oarepo_runtime.records.entity_resolvers.proxies import DraftProxy, RecordProxy
2
+
3
+ from invenio_records_resources.references import EntityResolver, RecordResolver
4
+ from invenio_users_resources.entity_resolvers import UserResolver, GroupResolver
5
+
6
+ __all__ = ["DraftProxy", "UserResolver", "GroupResolver", "RecordResolver", "EntityResolver", "RecordProxy"]
@@ -0,0 +1,48 @@
1
+ from invenio_pidstore.errors import PIDUnregistered
2
+
3
+ from invenio_records_resources.references.entity_resolvers.records import (
4
+ RecordProxy as InvenioRecordProxy,
5
+ )
6
+
7
+ from sqlalchemy.exc import NoResultFound
8
+
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
+
41
+ class DraftProxy(RecordProxy):
42
+ def _resolve(self):
43
+ pid_value = self._parse_ref_dict_id()
44
+ try:
45
+ return self.record_cls.pid.resolve(pid_value, registered_only=False)
46
+ except (PIDUnregistered, NoResultFound):
47
+ # try checking if it is a published record before failing
48
+ return self.record_cls.pid.resolve(pid_value)
@@ -34,6 +34,28 @@ class RecordItem(BaseRecordItem):
34
34
  class RecordList(BaseRecordList):
35
35
  components = []
36
36
 
37
+ @property
38
+ def aggregations(self):
39
+ """Get the search result aggregations."""
40
+ try:
41
+ result = super().aggregations
42
+ if result is None:
43
+ return result
44
+
45
+ for key in result.keys():
46
+ if 'buckets' in result[key]:
47
+ for bucket in result[key]['buckets']:
48
+ val = bucket['key']
49
+ label = bucket.get('label', '')
50
+
51
+ if not isinstance(val, str):
52
+ bucket['key'] = str(val)
53
+ if not isinstance(label, str):
54
+ bucket['label'] = str(label)
55
+ return result
56
+ except AttributeError:
57
+ return None
58
+
37
59
  @property
38
60
  def hits(self):
39
61
  """Iterator over the hits."""
@@ -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(lang_field, value_field):
14
- @validates(lang_field)
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_{lang_field}_{value_field}",
23
+ f"I18nSchema_{lang_name}_{value_name}",
21
24
  (Schema,),
22
25
  {
23
26
  "validate_lang": validate_lang,
24
- lang_field: fields.String(required=True),
25
- value_field: fields.String(required=True),
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, lang_field="lang", value_field="value", **kwargs
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(lang_field, value_field)),
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, lang_field="lang", value_field="value", **kwargs
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(lang_field, value_field),
48
+ get_i18n_schema(lang_name, value_name, value_field),
46
49
  *args,
47
50
  **kwargs,
48
51
  )
@@ -0,0 +1,74 @@
1
+ from functools import lru_cache
2
+
3
+ from marshmallow import Schema, fields
4
+ from marshmallow_utils.fields import SanitizedHTML
5
+ from invenio_base.utils import obj_or_import_string
6
+
7
+ @lru_cache
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)
10
+ return type(
11
+ f"I18nUISchema_{lang_name}_{value_name}",
12
+ (Schema,),
13
+ {
14
+ lang_name: fields.String(required=True),
15
+ value_name: value_field_class(required=True),
16
+ },
17
+ )
18
+
19
+
20
+ def MultilingualUIField( # noqa NOSONAR
21
+ *args, lang_name="lang", value_name="value", value_field="marshmallow_utils.fields.SanitizedHTML", **kwargs
22
+ ):
23
+ return fields.List(
24
+ fields.Nested(get_i18n_ui_schema(lang_name, value_name, value_field)),
25
+ **kwargs,
26
+ )
27
+
28
+
29
+ def I18nStrUIField( # noqa NOSONAR
30
+ *args, lang_name="lang", value_name="value", value_field="marshmallow_utils.fields.SanitizedHTML", **kwargs
31
+ ):
32
+ return fields.Nested(
33
+ get_i18n_ui_schema(lang_name, value_name, value_field),
34
+ *args,
35
+ **kwargs,
36
+ )
37
+
38
+
39
+ @lru_cache
40
+ def get_i18n_localized_ui_schema(lang_name, value_name):
41
+ class I18nLocalizedUISchema(Schema):
42
+ def _serialize(self, value, attr=None, obj=None, **kwargs):
43
+ if not value:
44
+ return None
45
+ language = self.context["locale"].language
46
+ for v in value:
47
+ if language == v[lang_name]:
48
+ return v[value_name]
49
+ return next(iter(value))[value_name]
50
+
51
+ # inherit to get a nice name for debugging
52
+ return type(
53
+ f"I18nLocalizedUISchema_{lang_name}_{value_name}",
54
+ (I18nLocalizedUISchema,),
55
+ {},
56
+ )
57
+
58
+
59
+ def MultilingualLocalizedUIField( # noqa NOSONAR
60
+ *args, lang_name="lang", value_name="value", **kwargs
61
+ ):
62
+ return fields.Nested(
63
+ get_i18n_localized_ui_schema(lang_name, value_name), **kwargs
64
+ )
65
+
66
+
67
+ def I18nStrLocalizedUIField( # noqa NOSONAR
68
+ *args, lang_name="lang", value_name="value", **kwargs
69
+ ):
70
+ return fields.Nested(
71
+ get_i18n_ui_schema(lang_name, value_name),
72
+ *args,
73
+ **kwargs,
74
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.33
3
+ Version: 1.5.35
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = oarepo-runtime
3
- version = 1.5.33
3
+ version = 1.5.35
4
4
  description = A set of runtime extensions of Invenio repository
5
5
  authors = Alzbeta Pokorna
6
6
  readme = README.md
@@ -8,7 +8,7 @@ long_description = file:README.md
8
8
  long_description_content_type = text/markdown
9
9
 
10
10
  [options]
11
- python = >=3.9
11
+ python = >=3.10
12
12
  install_requires =
13
13
  marshmallow
14
14
  langcodes
@@ -1,10 +0,0 @@
1
- from oarepo import __version__ as oarepo_version
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
9
-
10
- __all__ = ("gettext", "lazy_gettext", "get_locale")
@@ -1,90 +0,0 @@
1
- from oarepo import __version__ as oarepo_version
2
-
3
- from oarepo_runtime.records.entity_resolvers.proxies import DraftProxy
4
-
5
- # compatibility setting between invenio rdm 11 and invenio rdm 12
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"]
@@ -1,24 +0,0 @@
1
- from invenio_pidstore.errors import PIDUnregistered
2
- from oarepo import __version__ as oarepo_version
3
-
4
- # compatibility setting between invenio rdm 11 and invenio rdm 12
5
- # can be removed when invenio rdm 11 is no longer supported
6
- if oarepo_version.split(".")[0] == "11":
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
- )
12
-
13
- from sqlalchemy.exc import NoResultFound
14
-
15
-
16
- class DraftProxy(RecordProxy):
17
- def _resolve(self):
18
- pid_value = self._parse_ref_dict_id()
19
-
20
- try:
21
- return self.record_cls.pid.resolve(pid_value, registered_only=False)
22
- except (PIDUnregistered, NoResultFound):
23
- # try checking if it is a published record before failing
24
- return self.record_cls.pid.resolve(pid_value)
@@ -1,72 +0,0 @@
1
- from functools import lru_cache
2
-
3
- from marshmallow import Schema, fields
4
-
5
-
6
- @lru_cache
7
- def get_i18n_ui_schema(lang_field, value_field):
8
- return type(
9
- f"I18nUISchema_{lang_field}_{value_field}",
10
- (Schema,),
11
- {
12
- lang_field: fields.String(required=True),
13
- value_field: fields.String(required=True),
14
- },
15
- )
16
-
17
-
18
- def MultilingualUIField( # noqa NOSONAR
19
- *args, lang_field="lang", value_field="value", **kwargs
20
- ):
21
- return fields.List(
22
- fields.Nested(get_i18n_ui_schema(lang_field, value_field)),
23
- **kwargs,
24
- )
25
-
26
-
27
- def I18nStrUIField( # noqa NOSONAR
28
- *args, lang_field="lang", value_field="value", **kwargs
29
- ):
30
- return fields.Nested(
31
- get_i18n_ui_schema(lang_field, value_field),
32
- *args,
33
- **kwargs,
34
- )
35
-
36
-
37
- @lru_cache
38
- def get_i18n_localized_ui_schema(lang_field, value_field):
39
- class I18nLocalizedUISchema(Schema):
40
- def _serialize(self, value, attr=None, obj=None, **kwargs):
41
- if not value:
42
- return None
43
- language = self.context["locale"].language
44
- for v in value:
45
- if language == v[lang_field]:
46
- return v[value_field]
47
- return next(iter(value))[value_field]
48
-
49
- # inherit to get a nice name for debugging
50
- return type(
51
- f"I18nLocalizedUISchema_{lang_field}_{value_field}",
52
- (I18nLocalizedUISchema,),
53
- {},
54
- )
55
-
56
-
57
- def MultilingualLocalizedUIField( # noqa NOSONAR
58
- *args, lang_field="lang", value_field="value", **kwargs
59
- ):
60
- return fields.Nested(
61
- get_i18n_localized_ui_schema(lang_field, value_field), **kwargs
62
- )
63
-
64
-
65
- def I18nStrLocalizedUIField( # noqa NOSONAR
66
- *args, lang_field="lang", value_field="value", **kwargs
67
- ):
68
- return fields.Nested(
69
- get_i18n_ui_schema(lang_field, value_field),
70
- *args,
71
- **kwargs,
72
- )
File without changes