oarepo-runtime 1.5.59__py3-none-any.whl → 1.5.61__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- oarepo_runtime/records/relations/pid_relation.py +2 -0
- oarepo_runtime/records/systemfields/selectors.py +67 -2
- {oarepo_runtime-1.5.59.dist-info → oarepo_runtime-1.5.61.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.59.dist-info → oarepo_runtime-1.5.61.dist-info}/RECORD +8 -8
- {oarepo_runtime-1.5.59.dist-info → oarepo_runtime-1.5.61.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.59.dist-info → oarepo_runtime-1.5.61.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.59.dist-info → oarepo_runtime-1.5.61.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.59.dist-info → oarepo_runtime-1.5.61.dist-info}/top_level.txt +0 -0
@@ -35,6 +35,8 @@ class PIDRelationResult(RelationResult):
|
|
35
35
|
|
36
36
|
try:
|
37
37
|
obj = pid_field_context.resolve(id_)
|
38
|
+
if hasattr(obj, "relations") and obj.relations and hasattr(obj.relations, "dereference"):
|
39
|
+
obj.relations.dereference()
|
38
40
|
# We detach the related record model from the database session when
|
39
41
|
# we add it in the cache. Otherwise, accessing the cached record
|
40
42
|
# model, will execute a new select query after a db.session.commit.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any, List
|
1
|
+
from typing import Any, Callable, List
|
2
2
|
|
3
3
|
|
4
4
|
class Selector:
|
@@ -25,6 +25,71 @@ class FirstItemSelector(PathSelector):
|
|
25
25
|
return []
|
26
26
|
|
27
27
|
|
28
|
+
class FilteredSelector(Selector):
|
29
|
+
"""
|
30
|
+
Selector which filters output of another selector
|
31
|
+
Example:
|
32
|
+
FilteredSelector(PathSelector("metadata.creators", "metadata.contributors"),
|
33
|
+
filter=lambda x: x["nameType"] == "personal", projection="affiliations")
|
34
|
+
|
35
|
+
selects affiliations of creators with nameType personal from following data
|
36
|
+
|
37
|
+
data = {
|
38
|
+
"metadata": {
|
39
|
+
"creators": [
|
40
|
+
{"name": "hugo", "affiliations": ["uni1", "uni2"], "nameType": "personal"},
|
41
|
+
{"name": "uni3", "nameType": "organizational"},
|
42
|
+
]
|
43
|
+
}
|
44
|
+
}
|
45
|
+
"""
|
46
|
+
|
47
|
+
def __init__(
|
48
|
+
self,
|
49
|
+
selector: Selector,
|
50
|
+
filter: Callable[[Any], bool],
|
51
|
+
projection: Callable[[Any], Any] | str = None,
|
52
|
+
):
|
53
|
+
|
54
|
+
self.selector = selector
|
55
|
+
self.filter = filter
|
56
|
+
self.projection = projection
|
57
|
+
|
58
|
+
def select(self, record):
|
59
|
+
selected = self.selector.select(record)
|
60
|
+
selected = filter(self.filter, selected)
|
61
|
+
if self.projection:
|
62
|
+
ret = []
|
63
|
+
for select_element in selected:
|
64
|
+
if isinstance(self.projection, str):
|
65
|
+
if isinstance(select_element, dict) and self.projection in select_element:
|
66
|
+
result = select_element[self.projection]
|
67
|
+
else:
|
68
|
+
result = []
|
69
|
+
else:
|
70
|
+
result = self.projection(select_element)
|
71
|
+
if isinstance(result, list):
|
72
|
+
ret += result
|
73
|
+
else:
|
74
|
+
ret.append(result)
|
75
|
+
else:
|
76
|
+
ret = list(selected)
|
77
|
+
return ret
|
78
|
+
|
79
|
+
|
80
|
+
class MultiSelector(Selector):
|
81
|
+
"""Selector concatenating outputs of multiple selectors"""
|
82
|
+
|
83
|
+
def __init__(self, *selectors: Selector):
|
84
|
+
self.selectors = selectors
|
85
|
+
|
86
|
+
def select(self, record):
|
87
|
+
ret = []
|
88
|
+
for selector in self.selectors:
|
89
|
+
ret += selector.select(record)
|
90
|
+
return ret
|
91
|
+
|
92
|
+
|
28
93
|
def getter(data, path: List):
|
29
94
|
if len(path) == 0:
|
30
95
|
if isinstance(data, list):
|
@@ -36,4 +101,4 @@ def getter(data, path: List):
|
|
36
101
|
yield from getter(data[path[0]], path[1:])
|
37
102
|
elif isinstance(data, list):
|
38
103
|
for item in data:
|
39
|
-
yield from getter(item, path)
|
104
|
+
yield from getter(item, path)
|
@@ -54,7 +54,7 @@ oarepo_runtime/records/relations/__init__.py,sha256=bDAgxl_LdKsqpGG3qluxAkQnn5u2
|
|
54
54
|
oarepo_runtime/records/relations/base.py,sha256=XQpRt6-MfIKIClZ0IoGJr0GGl2Ru3RcqMoowOxrFG_E,8981
|
55
55
|
oarepo_runtime/records/relations/internal.py,sha256=OTp8iJqyl80sWDk0Q0AK42l6UsxZDABspVU_GwWza9o,1556
|
56
56
|
oarepo_runtime/records/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfSdpmjK0wvOFsEM,848
|
57
|
-
oarepo_runtime/records/relations/pid_relation.py,sha256=
|
57
|
+
oarepo_runtime/records/relations/pid_relation.py,sha256=jKiwUEepJkOc0MRX3Etl5RQJw3t40rY7FOJCIPwOKmg,2932
|
58
58
|
oarepo_runtime/records/systemfields/__init__.py,sha256=SPaMWM6t-azz6gZLUKvvXbOyE2_-LW6i_szQk8nhbAc,455
|
59
59
|
oarepo_runtime/records/systemfields/featured_file.py,sha256=MbSaYR130_o5S9gEOblnChq-PVK4xGPGpSCrzwG3cwc,1720
|
60
60
|
oarepo_runtime/records/systemfields/has_draftcheck.py,sha256=4JkMEefPLpqtPtlTgK3UT0KzTRgyw5_Qtkss2qcz5xk,1643
|
@@ -62,7 +62,7 @@ oarepo_runtime/records/systemfields/icu.py,sha256=sSGAgi5WhsAY4cCBL7-7nMpvHAuctp
|
|
62
62
|
oarepo_runtime/records/systemfields/mapping.py,sha256=tXOK_jkdY1pOUO7_VfChfDNB8UTi21GUXaidpugTnO8,1017
|
63
63
|
oarepo_runtime/records/systemfields/owner.py,sha256=dYRVBinniW7ECHuSnTAjeN6x1KhhJtNR9vxmD1KswMs,3805
|
64
64
|
oarepo_runtime/records/systemfields/record_status.py,sha256=U3kem4-JkNsT17e0iAl3HIAZ2MvO5lY_0U757aZvTKE,935
|
65
|
-
oarepo_runtime/records/systemfields/selectors.py,sha256=
|
65
|
+
oarepo_runtime/records/systemfields/selectors.py,sha256=xQEMhmqiE1M466cMilVO85V2DkELbbM3Xa8oYSCli8o,2959
|
66
66
|
oarepo_runtime/records/systemfields/synthetic.py,sha256=UustvhzcDGuaNZLDeHbWwshoxQR-qRIuHDCct5RXmrI,4287
|
67
67
|
oarepo_runtime/resources/__init__.py,sha256=v8BGrOTu_FjKzd0eozV7Q4GoGxyfybsL2cI-tbP5Pys,185
|
68
68
|
oarepo_runtime/resources/file_resource.py,sha256=Ta3bFce7l0xwqkkOMOEu9mxbB8BbKj5HUHRHmidhnl8,414
|
@@ -119,9 +119,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
119
119
|
oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
|
120
120
|
oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
|
121
121
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
122
|
-
oarepo_runtime-1.5.
|
123
|
-
oarepo_runtime-1.5.
|
124
|
-
oarepo_runtime-1.5.
|
125
|
-
oarepo_runtime-1.5.
|
126
|
-
oarepo_runtime-1.5.
|
127
|
-
oarepo_runtime-1.5.
|
122
|
+
oarepo_runtime-1.5.61.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
123
|
+
oarepo_runtime-1.5.61.dist-info/METADATA,sha256=HYDxnXTbb5364OERpt42GknlVXparLbK0fTws6JkS4A,4720
|
124
|
+
oarepo_runtime-1.5.61.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
125
|
+
oarepo_runtime-1.5.61.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
|
126
|
+
oarepo_runtime-1.5.61.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
127
|
+
oarepo_runtime-1.5.61.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|