oarepo-runtime 1.10.2__py3-none-any.whl → 2.0.0.dev3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. oarepo_runtime/__init__.py +24 -0
  2. oarepo_runtime/api.py +111 -0
  3. oarepo_runtime/cli/__init__.py +10 -21
  4. oarepo_runtime/cli/search.py +34 -0
  5. oarepo_runtime/config.py +86 -13
  6. oarepo_runtime/ext.py +64 -82
  7. oarepo_runtime/proxies.py +21 -5
  8. oarepo_runtime/records/__init__.py +11 -50
  9. oarepo_runtime/records/drafts.py +24 -18
  10. oarepo_runtime/records/mapping.py +84 -0
  11. oarepo_runtime/records/pid_providers.py +43 -7
  12. oarepo_runtime/records/systemfields/__init__.py +15 -33
  13. oarepo_runtime/records/systemfields/mapping.py +41 -24
  14. oarepo_runtime/records/systemfields/publication_status.py +59 -0
  15. oarepo_runtime/services/__init__.py +12 -0
  16. oarepo_runtime/services/config/__init__.py +15 -21
  17. oarepo_runtime/services/config/link_conditions.py +69 -75
  18. oarepo_runtime/services/config/permissions.py +62 -0
  19. oarepo_runtime/services/records/__init__.py +14 -1
  20. oarepo_runtime/services/records/links.py +21 -11
  21. oarepo_runtime/services/records/mapping.py +42 -0
  22. oarepo_runtime/services/results.py +98 -109
  23. oarepo_runtime/services/schema/__init__.py +12 -44
  24. oarepo_runtime/services/schema/i18n.py +47 -22
  25. oarepo_runtime/services/schema/i18n_ui.py +61 -24
  26. {oarepo_runtime-1.10.2.dist-info → oarepo_runtime-2.0.0.dev3.dist-info}/METADATA +9 -21
  27. oarepo_runtime-2.0.0.dev3.dist-info/RECORD +30 -0
  28. {oarepo_runtime-1.10.2.dist-info → oarepo_runtime-2.0.0.dev3.dist-info}/WHEEL +1 -2
  29. oarepo_runtime-2.0.0.dev3.dist-info/entry_points.txt +5 -0
  30. oarepo_runtime/cli/assets.py +0 -145
  31. oarepo_runtime/cli/base.py +0 -25
  32. oarepo_runtime/cli/cf.py +0 -15
  33. oarepo_runtime/cli/check.py +0 -167
  34. oarepo_runtime/cli/configuration.py +0 -51
  35. oarepo_runtime/cli/fixtures.py +0 -167
  36. oarepo_runtime/cli/index.py +0 -272
  37. oarepo_runtime/cli/permissions/__init__.py +0 -6
  38. oarepo_runtime/cli/permissions/base.py +0 -26
  39. oarepo_runtime/cli/permissions/evaluate.py +0 -63
  40. oarepo_runtime/cli/permissions/list.py +0 -239
  41. oarepo_runtime/cli/permissions/search.py +0 -121
  42. oarepo_runtime/cli/validate.py +0 -150
  43. oarepo_runtime/datastreams/__init__.py +0 -38
  44. oarepo_runtime/datastreams/asynchronous.py +0 -247
  45. oarepo_runtime/datastreams/catalogue.py +0 -150
  46. oarepo_runtime/datastreams/datastreams.py +0 -152
  47. oarepo_runtime/datastreams/errors.py +0 -54
  48. oarepo_runtime/datastreams/ext.py +0 -41
  49. oarepo_runtime/datastreams/fixtures.py +0 -265
  50. oarepo_runtime/datastreams/json.py +0 -4
  51. oarepo_runtime/datastreams/readers/__init__.py +0 -39
  52. oarepo_runtime/datastreams/readers/attachments.py +0 -51
  53. oarepo_runtime/datastreams/readers/excel.py +0 -123
  54. oarepo_runtime/datastreams/readers/json.py +0 -27
  55. oarepo_runtime/datastreams/readers/service.py +0 -54
  56. oarepo_runtime/datastreams/readers/yaml.py +0 -14
  57. oarepo_runtime/datastreams/semi_asynchronous.py +0 -91
  58. oarepo_runtime/datastreams/synchronous.py +0 -70
  59. oarepo_runtime/datastreams/transformers.py +0 -18
  60. oarepo_runtime/datastreams/types.py +0 -323
  61. oarepo_runtime/datastreams/utils.py +0 -131
  62. oarepo_runtime/datastreams/writers/__init__.py +0 -21
  63. oarepo_runtime/datastreams/writers/attachments_file.py +0 -92
  64. oarepo_runtime/datastreams/writers/attachments_service.py +0 -118
  65. oarepo_runtime/datastreams/writers/publish.py +0 -70
  66. oarepo_runtime/datastreams/writers/service.py +0 -175
  67. oarepo_runtime/datastreams/writers/utils.py +0 -30
  68. oarepo_runtime/datastreams/writers/validation_errors.py +0 -20
  69. oarepo_runtime/datastreams/writers/yaml.py +0 -56
  70. oarepo_runtime/ext_config.py +0 -67
  71. oarepo_runtime/i18n/__init__.py +0 -3
  72. oarepo_runtime/info/__init__.py +0 -0
  73. oarepo_runtime/info/check.py +0 -95
  74. oarepo_runtime/info/permissions/__init__.py +0 -0
  75. oarepo_runtime/info/permissions/debug.py +0 -191
  76. oarepo_runtime/info/views.py +0 -586
  77. oarepo_runtime/profile.py +0 -60
  78. oarepo_runtime/records/dumpers/__init__.py +0 -8
  79. oarepo_runtime/records/dumpers/edtf_interval.py +0 -38
  80. oarepo_runtime/records/dumpers/multilingual_dumper.py +0 -34
  81. oarepo_runtime/records/entity_resolvers/__init__.py +0 -13
  82. oarepo_runtime/records/entity_resolvers/proxies.py +0 -57
  83. oarepo_runtime/records/mappings/__init__.py +0 -0
  84. oarepo_runtime/records/mappings/rdm_parent_mapping.json +0 -483
  85. oarepo_runtime/records/owners/__init__.py +0 -3
  86. oarepo_runtime/records/owners/registry.py +0 -22
  87. oarepo_runtime/records/relations/__init__.py +0 -22
  88. oarepo_runtime/records/relations/base.py +0 -296
  89. oarepo_runtime/records/relations/internal.py +0 -46
  90. oarepo_runtime/records/relations/lookup.py +0 -28
  91. oarepo_runtime/records/relations/pid_relation.py +0 -102
  92. oarepo_runtime/records/systemfields/featured_file.py +0 -45
  93. oarepo_runtime/records/systemfields/has_draftcheck.py +0 -47
  94. oarepo_runtime/records/systemfields/icu.py +0 -371
  95. oarepo_runtime/records/systemfields/owner.py +0 -115
  96. oarepo_runtime/records/systemfields/record_status.py +0 -35
  97. oarepo_runtime/records/systemfields/selectors.py +0 -98
  98. oarepo_runtime/records/systemfields/synthetic.py +0 -130
  99. oarepo_runtime/resources/__init__.py +0 -4
  100. oarepo_runtime/resources/config.py +0 -12
  101. oarepo_runtime/resources/file_resource.py +0 -15
  102. oarepo_runtime/resources/json_serializer.py +0 -27
  103. oarepo_runtime/resources/localized_ui_json_serializer.py +0 -54
  104. oarepo_runtime/resources/resource.py +0 -53
  105. oarepo_runtime/resources/responses.py +0 -20
  106. oarepo_runtime/services/components.py +0 -429
  107. oarepo_runtime/services/config/draft_link.py +0 -23
  108. oarepo_runtime/services/config/permissions_presets.py +0 -174
  109. oarepo_runtime/services/config/service.py +0 -117
  110. oarepo_runtime/services/custom_fields/__init__.py +0 -80
  111. oarepo_runtime/services/custom_fields/mappings.py +0 -188
  112. oarepo_runtime/services/entity/__init__.py +0 -0
  113. oarepo_runtime/services/entity/config.py +0 -14
  114. oarepo_runtime/services/entity/schema.py +0 -9
  115. oarepo_runtime/services/entity/service.py +0 -48
  116. oarepo_runtime/services/expansions/__init__.py +0 -0
  117. oarepo_runtime/services/expansions/expandable_fields.py +0 -21
  118. oarepo_runtime/services/expansions/service.py +0 -4
  119. oarepo_runtime/services/facets/__init__.py +0 -33
  120. oarepo_runtime/services/facets/base.py +0 -12
  121. oarepo_runtime/services/facets/date.py +0 -72
  122. oarepo_runtime/services/facets/enum.py +0 -11
  123. oarepo_runtime/services/facets/facet_groups_names.py +0 -17
  124. oarepo_runtime/services/facets/max_facet.py +0 -13
  125. oarepo_runtime/services/facets/multilingual_facet.py +0 -33
  126. oarepo_runtime/services/facets/nested_facet.py +0 -32
  127. oarepo_runtime/services/facets/params.py +0 -192
  128. oarepo_runtime/services/facets/year_histogram.py +0 -200
  129. oarepo_runtime/services/files/__init__.py +0 -8
  130. oarepo_runtime/services/files/components.py +0 -62
  131. oarepo_runtime/services/files/service.py +0 -16
  132. oarepo_runtime/services/generators.py +0 -10
  133. oarepo_runtime/services/permissions/__init__.py +0 -3
  134. oarepo_runtime/services/permissions/generators.py +0 -103
  135. oarepo_runtime/services/relations/__init__.py +0 -0
  136. oarepo_runtime/services/relations/components.py +0 -15
  137. oarepo_runtime/services/relations/errors.py +0 -18
  138. oarepo_runtime/services/relations/mapping.py +0 -38
  139. oarepo_runtime/services/schema/cf.py +0 -13
  140. oarepo_runtime/services/schema/i18n_validation.py +0 -7
  141. oarepo_runtime/services/schema/marshmallow.py +0 -44
  142. oarepo_runtime/services/schema/marshmallow_to_json_schema.py +0 -72
  143. oarepo_runtime/services/schema/oneofschema.py +0 -192
  144. oarepo_runtime/services/schema/polymorphic.py +0 -21
  145. oarepo_runtime/services/schema/rdm.py +0 -75
  146. oarepo_runtime/services/schema/rdm_ui.py +0 -156
  147. oarepo_runtime/services/schema/ui.py +0 -251
  148. oarepo_runtime/services/schema/validation.py +0 -70
  149. oarepo_runtime/services/search.py +0 -282
  150. oarepo_runtime/services/service.py +0 -61
  151. oarepo_runtime/tasks.py +0 -6
  152. oarepo_runtime/translations/cs/LC_MESSAGES/messages.mo +0 -0
  153. oarepo_runtime/translations/cs/LC_MESSAGES/messages.po +0 -85
  154. oarepo_runtime/translations/default_translations.py +0 -6
  155. oarepo_runtime/translations/en/LC_MESSAGES/messages.mo +0 -0
  156. oarepo_runtime/translations/en/LC_MESSAGES/messages.po +0 -89
  157. oarepo_runtime/translations/messages.pot +0 -91
  158. oarepo_runtime/uow.py +0 -146
  159. oarepo_runtime/utils/__init__.py +0 -0
  160. oarepo_runtime/utils/functools.py +0 -37
  161. oarepo_runtime/utils/identity_utils.py +0 -35
  162. oarepo_runtime/utils/index.py +0 -11
  163. oarepo_runtime/utils/path.py +0 -97
  164. oarepo_runtime-1.10.2.dist-info/RECORD +0 -163
  165. oarepo_runtime-1.10.2.dist-info/entry_points.txt +0 -16
  166. oarepo_runtime-1.10.2.dist-info/top_level.txt +0 -2
  167. tests/marshmallow_to_json/__init__.py +0 -0
  168. tests/marshmallow_to_json/test_datacite_ui_schema.py +0 -1410
  169. tests/marshmallow_to_json/test_simple_schema.py +0 -52
  170. tests/pkg_data/__init__.py +0 -0
  171. {oarepo_runtime-1.10.2.dist-info → oarepo_runtime-2.0.0.dev3.dist-info}/licenses/LICENSE +0 -0
@@ -1,18 +0,0 @@
1
- class InvalidRelationError(KeyError):
2
- def __init__(self, message, related_id, location):
3
- self.related_id = related_id
4
- self.location = location
5
- super().__init__(message)
6
-
7
-
8
- class MultipleInvalidRelationErrors(Exception):
9
- """
10
- Records multiple validation errors of a relation field.
11
- self.errors is a list of pairs (path, Error)
12
- """
13
-
14
- def __init__(self, errors):
15
- super().__init__(
16
- "; ".join([f"{e[0]}: {type(e[1]).__name__}({e[1]})" for e in errors])
17
- )
18
- self.errors = errors
@@ -1,38 +0,0 @@
1
- class RelationsMapping:
2
- """Helper class for managing relation fields."""
3
-
4
- def __init__(self, record, fields):
5
- """Initialize the relations mapping."""
6
- # Needed because we overwrite __setattr__
7
- cache = {}
8
- self._fields = fields
9
- for name, fld in fields.items():
10
- field_value = fld.get_value(record, cache)
11
- setattr(self, name, field_value)
12
-
13
- def __iter__(self):
14
- """Iterate over the relations fields."""
15
- return iter(self._fields)
16
-
17
- def validate(self, fields=None):
18
- """Validates all relations in the record."""
19
- for name in fields or self:
20
- getattr(self, name).validate()
21
-
22
- def dereference(self, fields=None):
23
- """Dereferences relation fields."""
24
- for name in fields or self:
25
- getattr(self, name).dereference()
26
-
27
- def clean(self, fields=None):
28
- """Clean dereferenced relation fields."""
29
- for name in fields or self:
30
- getattr(self, name).clean()
31
-
32
- def set_cache(self, cache):
33
- from oarepo_runtime.records.relations import PIDRelation
34
-
35
- for key, fld in self._fields.items():
36
- if isinstance(fld, PIDRelation):
37
- fld.cache = cache
38
- getattr(self, key).cache = cache
@@ -1,13 +0,0 @@
1
- from invenio_records_resources.services.custom_fields.schema import (
2
- CustomFieldsSchemaUI as InvenioCustomFieldsSchemaUI,
3
- )
4
-
5
-
6
- class CustomFieldsSchemaUI(InvenioCustomFieldsSchemaUI):
7
- def _serialize(self, obj, **kwargs):
8
- self._schema.context.update(self.context)
9
- return super()._serialize(obj, **kwargs)
10
-
11
- def _deserialize(self, data, **kwargs):
12
- self._schema.context.update(self.context)
13
- return super()._deserialize(data, **kwargs)
@@ -1,7 +0,0 @@
1
- import langcodes
2
- from marshmallow.exceptions import ValidationError
3
-
4
-
5
- def lang_code_validator(value):
6
- if value != "_" and not langcodes.Language.get(value).is_valid():
7
- raise ValidationError(f"Invalid language code {value}")
@@ -1,44 +0,0 @@
1
- import typing
2
-
3
- from invenio_rdm_records.services.schemas.record import RDMRecordSchema
4
- from invenio_records_resources.services.records.schema import (
5
- BaseRecordSchema as InvenioBaseRecordSchema,
6
- )
7
-
8
- import marshmallow as ma
9
-
10
-
11
- class BaseRecordSchema(InvenioBaseRecordSchema):
12
- """Base record schema - in addition to invenio exposes $schema as well."""
13
-
14
- _schema = ma.fields.Str(attribute="$schema", data_key="$schema")
15
-
16
-
17
- class RDMBaseRecordSchema(RDMRecordSchema):
18
- """Base record schema - in addition to invenio exposes $schema as well."""
19
-
20
- _schema = ma.fields.Str(attribute="$schema", data_key="$schema")
21
-
22
-
23
- class DictOnlySchema(ma.Schema):
24
- def get_attribute(self, obj: typing.Any, attr: str, default: typing.Any):
25
- if not isinstance(attr, int) and "." in attr:
26
- return _get_value_for_keys_dict_only(obj, attr.split("."), default)
27
- else:
28
- return _get_value_for_key_dict_only(obj, attr, default)
29
-
30
-
31
- def _get_value_for_keys_dict_only(obj, keys, default):
32
- if len(keys) == 1:
33
- return _get_value_for_key_dict_only(obj, keys[0], default)
34
- else:
35
- return _get_value_for_keys_dict_only(
36
- _get_value_for_key_dict_only(obj, keys[0], default), keys[1:], default
37
- )
38
-
39
-
40
- def _get_value_for_key_dict_only(obj, key, default):
41
- try:
42
- return obj[key]
43
- except (KeyError, IndexError, TypeError, AttributeError):
44
- return default
@@ -1,72 +0,0 @@
1
- from marshmallow import Schema, fields
2
- from oarepo_runtime.services.schema.ui import (
3
- LocalizedEDTFTime,
4
- LocalizedDateTime,
5
- LocalizedEDTF,
6
- LocalizedEDTFInterval,
7
- LocalizedEDTFTimeInterval,
8
- LocalizedTime
9
- )
10
-
11
- field_type_converters = {
12
- fields.String : lambda field: {"type" : "string"},
13
- fields.Integer: lambda field: {"type": "integer"},
14
- fields.Float: lambda field: {"type": "number"},
15
- fields.Boolean: lambda field: {"type": "boolean"},
16
- fields.List: lambda field: {
17
- "type": "array",
18
- "items": convert_field_to_json_schema(field.inner)
19
- },
20
- fields.Nested: lambda field: {
21
- "type": "object",
22
- "properties": marshmallow_to_json_schema(field.schema)["properties"]
23
- },
24
- fields.Raw: lambda field: {
25
- "type": "object",
26
- 'additionalProperties' : True
27
- },
28
- LocalizedEDTFTime: lambda field: {
29
- "type": "string",
30
- "format": "date-time",
31
- },
32
- LocalizedDateTime: lambda field: {
33
- "type": "string",
34
- "format": "date-time",
35
- },
36
- LocalizedTime: lambda field: {
37
- "type": "string",
38
- "format": "time",
39
- },
40
- LocalizedEDTF: lambda field: {
41
- "type": "string",
42
- "format": "date",
43
- },
44
- LocalizedEDTFInterval: lambda field: {
45
- "type": "string",
46
- "format": "date-time",
47
- },
48
- LocalizedEDTFTimeInterval: lambda field: {
49
- "type": "string",
50
- "format": "date-time",
51
- }
52
- }
53
-
54
- def marshmallow_to_json_schema(schema:Schema) -> dict:
55
- json_schema = {
56
- 'type': 'object',
57
- 'properties': {}
58
- }
59
-
60
- for field_name, field in schema.fields.items():
61
- json_schema["properties"][field_name] = convert_field_to_json_schema(field)
62
-
63
- return json_schema
64
-
65
-
66
- def convert_field_to_json_schema(field:fields) -> dict:
67
- for field_type in type(field).mro():
68
- if field_type in field_type_converters:
69
- return field_type_converters[field_type](field)
70
-
71
- # no converter found, just string
72
- return {"type":"string"}
@@ -1,192 +0,0 @@
1
- import typing
2
-
3
- from marshmallow import Schema, ValidationError
4
-
5
-
6
- class OneOfSchema(Schema):
7
- """
8
- This is a special kind of schema that actually multiplexes other schemas
9
- based on object type. When serializing values, it uses get_obj_type() method
10
- to get object type name. Then it uses `type_schemas` name-to-Schema mapping
11
- to get schema for that particular object type, serializes object using that
12
- schema and adds an extra "type" field with name of object type.
13
- Deserialization is reverse.
14
-
15
- Example:
16
-
17
- class Foo(object):
18
- def __init__(self, foo):
19
- self.foo = foo
20
-
21
- class Bar(object):
22
- def __init__(self, bar):
23
- self.bar = bar
24
-
25
- class FooSchema(marshmallow.Schema):
26
- foo = marshmallow.fields.String(required=True)
27
-
28
- @marshmallow.post_load
29
- def make_foo(self, data, **kwargs):
30
- return Foo(**data)
31
-
32
- class BarSchema(marshmallow.Schema):
33
- bar = marshmallow.fields.Integer(required=True)
34
-
35
- @marshmallow.post_load
36
- def make_bar(self, data, **kwargs):
37
- return Bar(**data)
38
-
39
- class MyUberSchema(marshmallow.OneOfSchema):
40
- type_schemas = {
41
- 'foo': FooSchema,
42
- 'bar': BarSchema,
43
- }
44
-
45
- def get_obj_type(self, obj):
46
- if isinstance(obj, Foo):
47
- return 'foo'
48
- elif isinstance(obj, Bar):
49
- return 'bar'
50
- else:
51
- raise Exception('Unknown object type: %s' % repr(obj))
52
-
53
- MyUberSchema().dump([Foo(foo='hello'), Bar(bar=123)], many=True)
54
- # => [{'type': 'foo', 'foo': 'hello'}, {'type': 'bar', 'bar': 123}]
55
-
56
- You can control type field name added to serialized object representation by
57
- setting `type_field` class property.
58
- """
59
-
60
- type_field = "type"
61
- type_field_remove = True
62
- type_schemas: typing.Mapping[str, typing.Union[typing.Type[Schema], Schema]] = {}
63
-
64
- def get_obj_type(self, obj):
65
- """Returns name of the schema during dump() calls, given the object
66
- being dumped."""
67
- return obj.__class__.__name__
68
-
69
- def get_data_type(self, data):
70
- """Returns name of the schema during load() calls, given the data being
71
- loaded. Defaults to looking up `type_field` in the data."""
72
- data_type = data.get(self.type_field)
73
- if self.type_field in data and self.type_field_remove:
74
- data.pop(self.type_field)
75
- return data_type
76
-
77
- def dump(self, obj, *, many=None, **kwargs):
78
- errors = {}
79
- result_data = []
80
- result_errors = {}
81
- many = self.many if many is None else bool(many)
82
- if not many:
83
- result = result_data = self._dump(obj, **kwargs)
84
- else:
85
- for idx, o in enumerate(obj):
86
- try:
87
- result = self._dump(o, **kwargs)
88
- result_data.append(result)
89
- except ValidationError as error:
90
- result_errors[idx] = error.normalized_messages()
91
- result_data.append(error.valid_data)
92
-
93
- result = result_data
94
- errors = result_errors
95
-
96
- if not errors:
97
- return result
98
- else:
99
- exc = ValidationError(errors, data=obj, valid_data=result)
100
- raise exc
101
-
102
- def _dump(self, obj, *, update_fields=True, **kwargs):
103
- obj_type = self.get_obj_type(obj)
104
- if obj_type is None:
105
- return (
106
- None,
107
- {"_schema": "Unknown object class: %s" % obj.__class__.__name__},
108
- )
109
-
110
- type_schema = self.type_schemas.get(obj_type)
111
- if not type_schema:
112
- return None, {"_schema": "Unsupported object type: %s" % obj_type}
113
-
114
- schema = type_schema if isinstance(type_schema, Schema) else type_schema()
115
-
116
- schema.context.update(getattr(self, "context", {}))
117
-
118
- result = schema.dump(obj, many=False, **kwargs)
119
- if result is not None:
120
- result[self.type_field] = obj_type
121
- return result
122
-
123
- def load(self, data, *, many=None, partial=None, unknown=None, **kwargs):
124
- errors = {}
125
- result_data = []
126
- result_errors = {}
127
- many = self.many if many is None else bool(many)
128
- if partial is None:
129
- partial = self.partial
130
- if not many:
131
- try:
132
- result_data = self._load(
133
- data, partial=partial, unknown=unknown, **kwargs
134
- )
135
- except ValidationError as error:
136
- result_errors = error.normalized_messages()
137
- result_data = error.valid_data
138
- else:
139
- for idx, item in enumerate(data):
140
- try:
141
- result = self._load(item, partial=partial, **kwargs)
142
- result_data.append(result)
143
- except ValidationError as error:
144
- result_errors[idx] = error.normalized_messages()
145
- result_data.append(error.valid_data)
146
-
147
- result = result_data
148
- errors = result_errors
149
-
150
- if not errors:
151
- return result
152
- else:
153
- exc = ValidationError(errors, data=data, valid_data=result)
154
- raise exc
155
-
156
- def _load(self, data, *, partial=None, unknown=None, **kwargs):
157
- if not isinstance(data, dict):
158
- raise ValidationError({"_schema": "Invalid data type: %s" % data})
159
-
160
- data = dict(data)
161
- unknown = unknown or self.unknown
162
- data_type = self.get_data_type(data)
163
-
164
- if data_type is None:
165
- raise ValidationError(
166
- {self.type_field: ["Missing data for required field."]}
167
- )
168
-
169
- try:
170
- type_schema = self.type_schemas.get(data_type)
171
- except TypeError as error:
172
- # data_type could be unhashable
173
- raise ValidationError(
174
- {self.type_field: ["Invalid value: %s" % data_type]}
175
- ) from error
176
- if not type_schema:
177
- raise ValidationError(
178
- {self.type_field: ["Unsupported value: %s" % data_type]}
179
- )
180
-
181
- schema = type_schema if isinstance(type_schema, Schema) else type_schema()
182
-
183
- schema.context.update(getattr(self, "context", {}))
184
-
185
- return schema.load(data, many=False, partial=partial, unknown=unknown, **kwargs)
186
-
187
- def validate(self, data, *, many=None, partial=None):
188
- try:
189
- self.load(data, many=many, partial=partial)
190
- except ValidationError as ve:
191
- return ve.messages
192
- return {}
@@ -1,21 +0,0 @@
1
- from functools import cached_property
2
-
3
- import marshmallow as ma
4
-
5
- # from marshmallow_oneofschema import OneOfSchema
6
- from oarepo_runtime.services.schema.oneofschema import OneOfSchema
7
-
8
-
9
- class PolymorphicSchema(OneOfSchema):
10
- type_field_remove = False
11
-
12
- def get_obj_type(self, obj):
13
- return obj[self.type_field]
14
-
15
- @cached_property
16
- def type_schemas(self):
17
- ret = {}
18
- for key, fld in self.fields.items():
19
- if isinstance(fld, ma.fields.Nested):
20
- ret[fld.attribute or key] = type(fld.schema)
21
- return ret
@@ -1,75 +0,0 @@
1
- from functools import partial
2
-
3
- import marshmallow as ma
4
- from invenio_i18n.selectors import get_locale
5
- from invenio_rdm_records.services.schemas.metadata import record_identifiers_schemes
6
- from invenio_rdm_records.services.schemas.tombstone import DeletionStatusSchema
7
- from invenio_rdm_records.services.schemas.versions import VersionsSchema
8
- from invenio_vocabularies.contrib.awards.schema import AwardRelationSchema
9
- from invenio_vocabularies.contrib.funders.schema import FunderRelationSchema
10
- from marshmallow import fields as ma_fields
11
- from marshmallow import pre_load
12
- from marshmallow_utils.fields import (
13
- IdentifierSet,
14
- )
15
- from marshmallow_utils.fields.nestedattr import NestedAttribute
16
- from marshmallow_utils.schemas.identifier import IdentifierSchema
17
-
18
- from .i18n import MultilingualField
19
-
20
-
21
- class RDMRecordMixin(ma.Schema):
22
- versions = NestedAttribute(VersionsSchema, dump_only=True)
23
- deletion_status = ma_fields.Nested(DeletionStatusSchema, dump_only=True)
24
-
25
-
26
- class MultilingualAwardSchema(AwardRelationSchema):
27
- class Meta:
28
- unknown = ma.RAISE
29
-
30
- @pre_load()
31
- def convert_to_multilingual(self, data, many, **kwargs):
32
- if "title" in data and type(data["title"]) is str:
33
- lang = get_locale()
34
- data["title"] = {lang: data["title"]}
35
- return data
36
-
37
-
38
- class FundingSchema(ma.Schema):
39
- """Funding schema."""
40
-
41
- funder = ma_fields.Nested(FunderRelationSchema, required=True)
42
- award = ma_fields.Nested(MultilingualAwardSchema)
43
-
44
-
45
- class RecordIdentifierField(IdentifierSet):
46
- def __init__(self, *args, **kwargs):
47
- super().__init__(
48
- ma.fields.Nested(
49
- partial(IdentifierSchema, allowed_schemes=record_identifiers_schemes)
50
- ),
51
- *args,
52
- **kwargs
53
- )
54
-
55
-
56
- class RelatedRecordIdentifierField(IdentifierSet):
57
- def __init__(self, *args, **kwargs):
58
- super().__init__(
59
- ma.fields.Nested(
60
- partial(IdentifierSchema, allowed_schemes=record_identifiers_schemes)
61
- ),
62
- *args,
63
- **kwargs
64
- )
65
-
66
-
67
- class RDMSubjectSchema(ma.Schema):
68
- """Subject ui schema."""
69
-
70
- class Meta:
71
- unknown = ma.RAISE
72
-
73
- _id = ma.fields.String(data_key="id")
74
-
75
- subject = MultilingualField()
@@ -1,156 +0,0 @@
1
- import marshmallow as ma
2
- from idutils import to_url
3
- from oarepo_vocabularies.services.ui_schema import VocabularyI18nStrUIField
4
-
5
- from oarepo_runtime.services.schema.marshmallow import DictOnlySchema
6
-
7
- from .i18n_ui import MultilingualUIField
8
-
9
-
10
- class RDMIdentifierWithSchemaUISchema(ma.Schema):
11
- scheme = ma.fields.String(
12
- required=True,
13
- )
14
- identifier = ma.fields.String(required=True)
15
-
16
- @ma.post_dump
17
- def add_url(self, value, **kwargs):
18
- try:
19
- # ignore errors here
20
- if "identifier" in value and "scheme" in value:
21
- url = to_url(
22
- value["identifier"], value["scheme"].lower(), url_scheme="https"
23
- )
24
- if url:
25
- value["url"] = url
26
- except Exception:
27
- pass
28
- return value
29
-
30
-
31
- class RDMAwardIdentifierUISchema(ma.Schema):
32
- identifier = ma.fields.String()
33
-
34
-
35
- class RDMAwardSubjectUISchema(ma.Schema):
36
- _id = ma.fields.String(data_key="id")
37
-
38
- subject = ma.fields.String()
39
-
40
-
41
- class RDMAwardOrganizationUISchema(ma.Schema):
42
- schema = ma.fields.String()
43
-
44
- _id = ma.fields.String(data_key="id")
45
-
46
- organization = ma.fields.String()
47
-
48
-
49
- class RDMFunderVocabularyUISchema(DictOnlySchema):
50
- class Meta:
51
- unknown = ma.INCLUDE
52
-
53
- _id = ma.fields.String(data_key="id", attribute="id")
54
-
55
- _version = ma.fields.String(data_key="@v", attribute="@v")
56
-
57
- name = ma.fields.String()
58
-
59
- identifiers = ma.fields.List(ma.fields.Nested(RDMIdentifierWithSchemaUISchema()))
60
-
61
-
62
- class RDMRoleVocabularyUISchema(DictOnlySchema):
63
- class Meta:
64
- unknown = ma.INCLUDE
65
-
66
- _id = ma.fields.String(data_key="id", attribute="id")
67
-
68
- _version = ma.fields.String(data_key="@v", attribute="@v")
69
-
70
- title = VocabularyI18nStrUIField()
71
-
72
-
73
- class RDMAwardVocabularyUISchema(DictOnlySchema):
74
- class Meta:
75
- unknown = ma.INCLUDE
76
-
77
- _id = ma.fields.String(data_key="id", attribute="id")
78
-
79
- _version = ma.fields.String(data_key="@v", attribute="@v")
80
-
81
- title = VocabularyI18nStrUIField()
82
-
83
- number = ma.fields.String()
84
-
85
- identifier = ma.fields.List(ma.fields.Nested(RDMAwardIdentifierUISchema()))
86
-
87
- acronym = ma.fields.String()
88
-
89
- program = ma.fields.String()
90
-
91
- subjects = ma.fields.List(ma.fields.Nested(RDMAwardSubjectUISchema()))
92
-
93
- organizations = ma.fields.List(ma.fields.Nested(RDMAwardOrganizationUISchema()))
94
-
95
-
96
- class RDMFundersUISchema(ma.Schema):
97
- """Funding ui schema."""
98
-
99
- class Meta:
100
- unknown = ma.RAISE
101
-
102
- funder = ma.fields.Nested(lambda: RDMFunderVocabularyUISchema())
103
-
104
- award = ma.fields.Nested(lambda: RDMAwardVocabularyUISchema())
105
-
106
-
107
- class RDMPersonOrOrganizationUISchema(ma.Schema):
108
- class Meta:
109
- unknown = ma.INCLUDE
110
-
111
- name = ma.fields.String()
112
-
113
- type = ma.fields.String()
114
-
115
- given_name = ma.fields.String()
116
-
117
- family_name = ma.fields.String()
118
-
119
- identifiers = ma.fields.List(ma.fields.Nested(RDMIdentifierWithSchemaUISchema()))
120
-
121
-
122
- class RDMAffiliationVocabularyUISchema(DictOnlySchema):
123
- class Meta:
124
- unknown = ma.INCLUDE
125
-
126
- _id = ma.fields.String(data_key="id", attribute="id")
127
-
128
- _version = ma.fields.String(data_key="@v", attribute="@v")
129
-
130
- name = ma.fields.String()
131
-
132
-
133
- class RDMCreatorsUISchema(ma.Schema):
134
- """Funding ui schema."""
135
-
136
- class Meta:
137
- unknown = ma.RAISE
138
-
139
- role = ma.fields.Nested(lambda: RDMRoleVocabularyUISchema())
140
-
141
- affiliations = ma.fields.List(
142
- ma.fields.Nested(lambda: RDMAffiliationVocabularyUISchema())
143
- )
144
-
145
- person_or_org = ma.fields.Nested(RDMPersonOrOrganizationUISchema())
146
-
147
-
148
- class RDMSubjectUISchema(ma.Schema):
149
- """Subject ui schema."""
150
-
151
- class Meta:
152
- unknown = ma.RAISE
153
-
154
- _id = ma.fields.String(data_key="id")
155
-
156
- subject = MultilingualUIField()