oarepo-runtime 1.5.11__py3-none-any.whl → 1.5.13__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.
- oarepo_runtime/records/systemfields/__init__.py +6 -0
- oarepo_runtime/records/systemfields/mapping.py +0 -2
- oarepo_runtime/records/systemfields/selectors.py +38 -0
- oarepo_runtime/records/systemfields/synthetic.py +45 -13
- oarepo_runtime/services/config/service.py +5 -4
- oarepo_runtime/services/results.py +0 -1
- oarepo_runtime/utils/functools.py +2 -2
- {oarepo_runtime-1.5.11.dist-info → oarepo_runtime-1.5.13.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.11.dist-info → oarepo_runtime-1.5.13.dist-info}/RECORD +13 -12
- {oarepo_runtime-1.5.11.dist-info → oarepo_runtime-1.5.13.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.11.dist-info → oarepo_runtime-1.5.13.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.11.dist-info → oarepo_runtime-1.5.13.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.11.dist-info → oarepo_runtime-1.5.13.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,7 @@
|
|
1
1
|
from .icu import ICUField, ICUSortField, ICUSuggestField
|
2
2
|
from .mapping import MappingSystemFieldMixin, SystemFieldDumperExt
|
3
|
+
from .selectors import FirstItemSelector, PathSelector, Selector
|
4
|
+
from .synthetic import SyntheticSystemField
|
3
5
|
|
4
6
|
__all__ = (
|
5
7
|
"ICUField",
|
@@ -7,4 +9,8 @@ __all__ = (
|
|
7
9
|
"ICUSortField",
|
8
10
|
"MappingSystemFieldMixin",
|
9
11
|
"SystemFieldDumperExt",
|
12
|
+
"SyntheticSystemField",
|
13
|
+
"PathSelector",
|
14
|
+
"Selector",
|
15
|
+
"FirstItemSelector",
|
10
16
|
)
|
@@ -19,12 +19,10 @@ class MappingSystemFieldMixin:
|
|
19
19
|
@classmethod
|
20
20
|
def search_dump(cls, data, record):
|
21
21
|
"""Dump custom field."""
|
22
|
-
pass
|
23
22
|
|
24
23
|
@classmethod
|
25
24
|
def search_load(cls, data, record_cls):
|
26
25
|
"""Load custom field."""
|
27
|
-
pass
|
28
26
|
|
29
27
|
|
30
28
|
class SystemFieldDumperExt(SearchDumperExt):
|
@@ -0,0 +1,38 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
|
4
|
+
class Selector:
|
5
|
+
def select(self, record):
|
6
|
+
return []
|
7
|
+
|
8
|
+
|
9
|
+
class PathSelector:
|
10
|
+
def __init__(self, *paths):
|
11
|
+
self.paths = [x.split(".") for x in paths]
|
12
|
+
|
13
|
+
def select(self, record):
|
14
|
+
ret = []
|
15
|
+
for path in self.paths:
|
16
|
+
for rec in getter(record, path):
|
17
|
+
ret.append(rec)
|
18
|
+
return ret
|
19
|
+
|
20
|
+
|
21
|
+
class FirstItemSelector(PathSelector):
|
22
|
+
def select(self, record):
|
23
|
+
for rec in super().select(record):
|
24
|
+
return [rec]
|
25
|
+
|
26
|
+
|
27
|
+
def getter(data, path: List):
|
28
|
+
if len(path) == 0:
|
29
|
+
if isinstance(data, list):
|
30
|
+
yield from data
|
31
|
+
else:
|
32
|
+
yield data
|
33
|
+
elif isinstance(data, dict):
|
34
|
+
if path[0] in data:
|
35
|
+
yield from getter(data[path[0]], path[1:])
|
36
|
+
elif isinstance(data, list):
|
37
|
+
for item in data:
|
38
|
+
yield from getter(item, path)
|
@@ -12,20 +12,23 @@ class SyntheticSystemField(MappingSystemFieldMixin, SystemField):
|
|
12
12
|
the record is being indexed.
|
13
13
|
|
14
14
|
Usage:
|
15
|
-
|
16
|
-
|
17
|
-
2.
|
18
|
-
either a dictionary or an instance of the record class)
|
19
|
-
3. Put the class onto the record. If you use oarepo-model-builder, add it to the model
|
15
|
+
1. Check if any of the provided selectors (oarepo_runtime.records.systemfields.selectors)
|
16
|
+
are usable for your use case. If not, create a subclass of Selector class.
|
17
|
+
2. Put this class onto the record. If you use oarepo-model-builder, add it to the model
|
20
18
|
like:
|
21
19
|
```yaml
|
22
20
|
record:
|
23
21
|
record:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
imports:
|
23
|
+
- oarepo_runtime.records.systemfields.SyntheticSystemField
|
24
|
+
- oarepo_vocabularies.records.selectors.LevelSelector
|
25
|
+
fields:
|
26
|
+
faculty = SyntheticSystemField(selector=LevelSelector("metadata.thesis.degreeGrantors", level=1))
|
27
|
+
department = SyntheticSystemField(selector=LevelSelector("metadata.thesis.degreeGrantors", level=2))
|
28
|
+
defenseYear = |
|
29
|
+
SyntheticSystemField(selector=PathSelector("metadata.thesis.dateDefended"),
|
30
|
+
transformer=lambda x: x[:4]
|
31
|
+
)
|
29
32
|
```
|
30
33
|
|
31
34
|
4. Add the extra fields to the mapping and facets. If using oarepo-model-builder, add it to the
|
@@ -62,13 +65,32 @@ class SyntheticSystemField(MappingSystemFieldMixin, SystemField):
|
|
62
65
|
```
|
63
66
|
"""
|
64
67
|
|
68
|
+
def __init__(self, selector=None, filter=None, map=None, key=None, **kwargs):
|
69
|
+
self.selector = selector
|
70
|
+
self.map = map
|
71
|
+
self.filter = filter
|
72
|
+
super().__init__(key=key, **kwargs)
|
73
|
+
|
65
74
|
def search_dump(self, data, record):
|
66
75
|
dt = self._value(data)
|
67
76
|
if dt:
|
68
|
-
|
77
|
+
key = self.key.split(".")
|
78
|
+
d = data
|
79
|
+
for k in key[:-1]:
|
80
|
+
d = d.setdefault(k, {})
|
81
|
+
d[key[-1]] = dt
|
69
82
|
|
70
83
|
def search_load(self, data, record_cls):
|
71
|
-
|
84
|
+
def remove_key(d, key):
|
85
|
+
if len(key) == 1:
|
86
|
+
d.pop(key[0], None)
|
87
|
+
else:
|
88
|
+
if not isinstance(d, dict) or key[0] not in d:
|
89
|
+
return
|
90
|
+
remove_key(d[key[0]], key[1:])
|
91
|
+
if not d[key[0]]:
|
92
|
+
d.pop(key[0])
|
93
|
+
remove_key(data, self.key.split("."))
|
72
94
|
|
73
95
|
def __get__(self, record, owner=None):
|
74
96
|
if record is None:
|
@@ -76,4 +98,14 @@ class SyntheticSystemField(MappingSystemFieldMixin, SystemField):
|
|
76
98
|
return self._value(record)
|
77
99
|
|
78
100
|
def _value(self, data):
|
79
|
-
|
101
|
+
if self.selector:
|
102
|
+
value = list(self.selector.select(data))
|
103
|
+
if self.filter:
|
104
|
+
value = [x for x in value if self.filter(x)]
|
105
|
+
if self.map:
|
106
|
+
value = [self.map(x) for x in value]
|
107
|
+
value = [x for x in value if x is not None]
|
108
|
+
return value
|
109
|
+
raise ValueError(
|
110
|
+
"Please either provide a selector or subclass this class and implement a _value method"
|
111
|
+
)
|
@@ -54,8 +54,7 @@ class PermissionsPresetsConfigMixin:
|
|
54
54
|
"""
|
55
55
|
registered_preset_classes = current_app.config["OAREPO_PERMISSIONS_PRESETS"]
|
56
56
|
preset_classes = [
|
57
|
-
registered_preset_classes[x]
|
58
|
-
for x in cls._get_permissions_presets()
|
57
|
+
registered_preset_classes[x] for x in cls._get_permissions_presets()
|
59
58
|
]
|
60
59
|
if hasattr(cls, "base_permission_policy_cls"):
|
61
60
|
preset_classes.insert(0, cls.base_permission_policy_cls)
|
@@ -72,7 +71,9 @@ class PermissionsPresetsConfigMixin:
|
|
72
71
|
config_key = cls._get_presents_config_key()
|
73
72
|
if config_key in current_app.config:
|
74
73
|
return current_app.config[config_key]
|
75
|
-
return
|
74
|
+
return (
|
75
|
+
cls.PERMISSIONS_PRESETS
|
76
|
+
) # noqa (omitted here because of the order of mixins)
|
76
77
|
|
77
78
|
@classmethod
|
78
79
|
def _get_presents_config_key(cls):
|
@@ -93,5 +94,5 @@ class PermissionsPresetsConfigMixin:
|
|
93
94
|
name = cls.__name__
|
94
95
|
if name.endswith("Config"):
|
95
96
|
name = name[:-6]
|
96
|
-
name = re.sub(r
|
97
|
+
name = re.sub(r"(?<!^)(?=[A-Z])", "_", name).upper()
|
97
98
|
return f"{name}_PERMISSIONS_PRESETS"
|
@@ -24,9 +24,9 @@ class class_property:
|
|
24
24
|
self.__name__ = info.__name__
|
25
25
|
self.__module__ = info.__module__
|
26
26
|
|
27
|
-
def __get__(self, obj, type=None):
|
27
|
+
def __get__(self, obj, type=None): # NOSONAR - this is a descriptor
|
28
28
|
if obj and type is None:
|
29
|
-
type = obj.__class__
|
29
|
+
type = obj.__class__ # NOSONAR - this is a descriptor
|
30
30
|
return self.__get.__get__(obj, type)()
|
31
31
|
|
32
32
|
def __set__(self, obj, value):
|
@@ -53,22 +53,23 @@ oarepo_runtime/records/relations/base.py,sha256=XQpRt6-MfIKIClZ0IoGJr0GGl2Ru3Rcq
|
|
53
53
|
oarepo_runtime/records/relations/internal.py,sha256=OTp8iJqyl80sWDk0Q0AK42l6UsxZDABspVU_GwWza9o,1556
|
54
54
|
oarepo_runtime/records/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfSdpmjK0wvOFsEM,848
|
55
55
|
oarepo_runtime/records/relations/pid_relation.py,sha256=zJjSf_ocFBViYsOuMMZLbQZpNZeKiOK33dPD4tk74Qo,2786
|
56
|
-
oarepo_runtime/records/systemfields/__init__.py,sha256=
|
56
|
+
oarepo_runtime/records/systemfields/__init__.py,sha256=SPaMWM6t-azz6gZLUKvvXbOyE2_-LW6i_szQk8nhbAc,455
|
57
57
|
oarepo_runtime/records/systemfields/featured_file.py,sha256=MbSaYR130_o5S9gEOblnChq-PVK4xGPGpSCrzwG3cwc,1720
|
58
58
|
oarepo_runtime/records/systemfields/has_draftcheck.py,sha256=3XLRsZJWRpT4BFF1HTg6C27ECVmIcZ4RrdGzYC8S7v0,1518
|
59
59
|
oarepo_runtime/records/systemfields/icu.py,sha256=tAwplzy9y7C9Dm7HqcGZsDu2AKqVGXhCbKLsFlgVWg8,5921
|
60
|
-
oarepo_runtime/records/systemfields/mapping.py,sha256=
|
60
|
+
oarepo_runtime/records/systemfields/mapping.py,sha256=tXOK_jkdY1pOUO7_VfChfDNB8UTi21GUXaidpugTnO8,1017
|
61
61
|
oarepo_runtime/records/systemfields/record_status.py,sha256=U3kem4-JkNsT17e0iAl3HIAZ2MvO5lY_0U757aZvTKE,935
|
62
|
-
oarepo_runtime/records/systemfields/
|
62
|
+
oarepo_runtime/records/systemfields/selectors.py,sha256=bgH6oalv9rPPC-EVwt8-DdkUl7EX0UOgfynN51DZauI,882
|
63
|
+
oarepo_runtime/records/systemfields/synthetic.py,sha256=hXBDEcyqWtytPhwypC5ZKDhF4Gr3kVoq3lhpBsUNvrY,3729
|
63
64
|
oarepo_runtime/resources/__init__.py,sha256=v8BGrOTu_FjKzd0eozV7Q4GoGxyfybsL2cI-tbP5Pys,185
|
64
65
|
oarepo_runtime/resources/file_resource.py,sha256=Ta3bFce7l0xwqkkOMOEu9mxbB8BbKj5HUHRHmidhnl8,414
|
65
66
|
oarepo_runtime/resources/localized_ui_json_serializer.py,sha256=4Kle34k-_uu3Y9JJ2vAXcQ9DqYRxXgy-_iZhiFuukmE,1684
|
66
67
|
oarepo_runtime/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
67
|
-
oarepo_runtime/services/results.py,sha256=
|
68
|
+
oarepo_runtime/services/results.py,sha256=F3A0U3MRUOYlxNglJPQeGMKdD8QNq1il106jQZ0c9gQ,1499
|
68
69
|
oarepo_runtime/services/search.py,sha256=ywfwGH7oAM44WeOSjlIsY_qoCMZJ1TlTLd_NgE2ow3Y,5296
|
69
70
|
oarepo_runtime/services/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
70
71
|
oarepo_runtime/services/config/permissions_presets.py,sha256=zApeA-2DYAlD--SzVz3vq_OFjq48Ko0pe08e4o2vxr4,6114
|
71
|
-
oarepo_runtime/services/config/service.py,sha256=
|
72
|
+
oarepo_runtime/services/config/service.py,sha256=8qFLIqDi2zPby4Y-vgGlf1iJIBJOsEEsaw1t8ml96H8,3880
|
72
73
|
oarepo_runtime/services/custom_fields/__init__.py,sha256=xJ7XEyMJHPfIgX5JKpgpwh7SYc9Zee2dC5oC8cm99Qc,2282
|
73
74
|
oarepo_runtime/services/custom_fields/mappings.py,sha256=1mb8nYeUlQxbBolsKURGKUIpIV1NDb-7Mcur32jjIjg,4433
|
74
75
|
oarepo_runtime/services/expansions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -105,12 +106,12 @@ oarepo_runtime/translations/cs/LC_MESSAGES/messages.po,sha256=vGZQo5NlTtj_qsJuDw
|
|
105
106
|
oarepo_runtime/translations/en/LC_MESSAGES/messages.mo,sha256=FKAl1wlg2NhtQ1-9U2dkUwcotR959j5GuUKJygCYpwI,445
|
106
107
|
oarepo_runtime/translations/en/LC_MESSAGES/messages.po,sha256=rZ2PGvkcJbmuwrWeFX5edk0zJIzZnL83M9HSAceDP_U,1193
|
107
108
|
oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
108
|
-
oarepo_runtime/utils/functools.py,sha256=
|
109
|
+
oarepo_runtime/utils/functools.py,sha256=7V-aMkAscc5qyGawGS8jmwqfdW2Wpjxe-u8DKgB8meI,1325
|
109
110
|
oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
|
110
111
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
111
|
-
oarepo_runtime-1.5.
|
112
|
-
oarepo_runtime-1.5.
|
113
|
-
oarepo_runtime-1.5.
|
114
|
-
oarepo_runtime-1.5.
|
115
|
-
oarepo_runtime-1.5.
|
116
|
-
oarepo_runtime-1.5.
|
112
|
+
oarepo_runtime-1.5.13.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
113
|
+
oarepo_runtime-1.5.13.dist-info/METADATA,sha256=JHKX3me9P-WP93ItF4WVIfeIgB0wFFug0MYiV3cJBoA,4787
|
114
|
+
oarepo_runtime-1.5.13.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
115
|
+
oarepo_runtime-1.5.13.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
|
116
|
+
oarepo_runtime-1.5.13.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
117
|
+
oarepo_runtime-1.5.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|