oarepo-runtime 2.0.0.dev16__py3-none-any.whl → 2.0.0.dev18__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/__init__.py +1 -1
- oarepo_runtime/services/generators.py +53 -6
- {oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/METADATA +1 -1
- {oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/RECORD +7 -7
- {oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/WHEEL +0 -0
- {oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/licenses/LICENSE +0 -0
oarepo_runtime/__init__.py
CHANGED
@@ -10,20 +10,21 @@
|
|
10
10
|
|
11
11
|
from __future__ import annotations
|
12
12
|
|
13
|
-
from abc import abstractmethod
|
13
|
+
from abc import ABC, abstractmethod
|
14
|
+
from itertools import chain
|
14
15
|
from typing import TYPE_CHECKING, Any, override
|
15
16
|
|
16
17
|
from invenio_records_permissions.generators import (
|
17
18
|
ConditionalGenerator as InvenioConditionalGenerator,
|
18
19
|
)
|
19
20
|
from invenio_records_permissions.generators import Generator as InvenioGenerator
|
21
|
+
from invenio_search.engine import dsl
|
20
22
|
|
21
23
|
if TYPE_CHECKING:
|
22
24
|
from collections.abc import Sequence
|
23
25
|
|
24
26
|
from flask_principal import Need
|
25
27
|
from invenio_records_resources.records.api import Record
|
26
|
-
from invenio_search.engine import dsl
|
27
28
|
|
28
29
|
|
29
30
|
class Generator(InvenioGenerator):
|
@@ -45,7 +46,7 @@ class Generator(InvenioGenerator):
|
|
45
46
|
return super().query_filter(**kwargs) # type: ignore[no-any-return]
|
46
47
|
|
47
48
|
|
48
|
-
class ConditionalGenerator(InvenioConditionalGenerator):
|
49
|
+
class ConditionalGenerator(InvenioConditionalGenerator, ABC):
|
49
50
|
"""Typed conditional generator.
|
50
51
|
|
51
52
|
This class will be removed when invenio has proper type stubs.
|
@@ -58,7 +59,7 @@ class ConditionalGenerator(InvenioConditionalGenerator):
|
|
58
59
|
@abstractmethod
|
59
60
|
def _condition(self, **kwargs: Any) -> bool:
|
60
61
|
"""Condition to choose generators set."""
|
61
|
-
raise NotImplementedError # pragma:
|
62
|
+
raise NotImplementedError # pragma: no cover
|
62
63
|
|
63
64
|
def _generators(self, record: Record, **kwargs: Any) -> Sequence[InvenioGenerator]:
|
64
65
|
"""Get the "then" or "else" generators."""
|
@@ -72,6 +73,52 @@ class ConditionalGenerator(InvenioConditionalGenerator):
|
|
72
73
|
def excludes(self, **kwargs: Any) -> Sequence[Need]: # type: ignore[override]
|
73
74
|
return super().excludes(**kwargs) # type: ignore[no-any-return]
|
74
75
|
|
76
|
+
@abstractmethod
|
77
|
+
def _query_instate(self, **context: Any) -> dsl.query.Query:
|
78
|
+
raise NotImplementedError # pragma: no cover
|
79
|
+
|
75
80
|
@override
|
76
|
-
def query_filter(self, **
|
77
|
-
|
81
|
+
def query_filter(self, **context: Any) -> dsl.query.Query: # type: ignore[reportIncompatibleMethodOverride]
|
82
|
+
"""Apply then or else filter."""
|
83
|
+
then_query = super()._make_query(self.then_, **context)
|
84
|
+
else_query = super()._make_query(self.else_, **context)
|
85
|
+
|
86
|
+
q_instate = self._query_instate(**context)
|
87
|
+
q_outstate = ~q_instate
|
88
|
+
|
89
|
+
if then_query and else_query:
|
90
|
+
ret = (q_instate & then_query) | (q_outstate & else_query)
|
91
|
+
elif then_query:
|
92
|
+
ret = q_instate & then_query
|
93
|
+
elif else_query:
|
94
|
+
ret = q_outstate & else_query
|
95
|
+
else:
|
96
|
+
ret = dsl.Q("match_none")
|
97
|
+
|
98
|
+
return ret
|
99
|
+
|
100
|
+
|
101
|
+
class AggregateGenerator(Generator, ABC):
|
102
|
+
"""Superclass for generators aggregating multiple generators."""
|
103
|
+
|
104
|
+
@abstractmethod
|
105
|
+
def _generators(self, **context: Any) -> Sequence[InvenioGenerator]:
|
106
|
+
"""Return the generators."""
|
107
|
+
raise NotImplementedError # pragma: no cover
|
108
|
+
|
109
|
+
@override
|
110
|
+
def needs(self, **context: Any) -> Sequence[Need]:
|
111
|
+
"""Get the needs from the policy."""
|
112
|
+
needs = [generator.needs(**context) for generator in self._generators(**context)]
|
113
|
+
return list(chain.from_iterable(needs))
|
114
|
+
|
115
|
+
@override
|
116
|
+
def excludes(self, **context: Any) -> Sequence[Need]:
|
117
|
+
"""Get the excludes from the policy."""
|
118
|
+
excludes = [generator.excludes(**context) for generator in self._generators(**context)]
|
119
|
+
return list(chain.from_iterable(excludes))
|
120
|
+
|
121
|
+
@override
|
122
|
+
def query_filter(self, **context: Any) -> dsl.query.Query:
|
123
|
+
"""Search filters."""
|
124
|
+
return ConditionalGenerator._make_query(self._generators(**context), **context) # noqa SLF001 # type: ignore[reportReturnType]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
oarepo_runtime/__init__.py,sha256=
|
1
|
+
oarepo_runtime/__init__.py,sha256=6z9_8CzYNGg5SzI-1U_6PbV9AZfjt6baMAwbuggSoQs,686
|
2
2
|
oarepo_runtime/api.py,sha256=7gPeRS66moT1lIedPRmuK0EnB8PpGO7iD5eRCQOty4U,12552
|
3
3
|
oarepo_runtime/config.py,sha256=RUEPFn_5bKp9Wb0OY-Fb3VK30m35vF5IsLjYaQHhP3g,3838
|
4
4
|
oarepo_runtime/ext.py,sha256=G9j5IgnVPdE656qaiN4RllpOkdyToP8v9uwas3DdpTY,8451
|
@@ -16,7 +16,7 @@ oarepo_runtime/records/systemfields/publication_status.py,sha256=1g3VXNPh0FsiPCp
|
|
16
16
|
oarepo_runtime/resources/__init__.py,sha256=voynQULXoOEviADkbOpekMphZPTAz4IOTg5BF9xPwTM,453
|
17
17
|
oarepo_runtime/resources/config.py,sha256=hJewyZ2FlEm4TtYnQS9JsnKnA6hhtSbvo1PC24-7f7Y,980
|
18
18
|
oarepo_runtime/services/__init__.py,sha256=OGtBgEeaDTyk2RPDNXuKbU9_7egFBZr42SM0gN5FrF4,341
|
19
|
-
oarepo_runtime/services/generators.py,sha256=
|
19
|
+
oarepo_runtime/services/generators.py,sha256=DCzqL00x4PCqHySITU1RZgZ__kL_mav46dfrgUxtswI,4618
|
20
20
|
oarepo_runtime/services/results.py,sha256=fk-Enx_LwZLbw81yZ7CXVTku86vd3_fjprnb8l5sFHk,6657
|
21
21
|
oarepo_runtime/services/config/__init__.py,sha256=SX1kfIGk8HkohdLQrNpRQUTltksEyDcCa-kFXxrX4e8,711
|
22
22
|
oarepo_runtime/services/config/components.py,sha256=cyU-JeMzLuBL-9JkUKbUQuu527WAq0yptGs6806XSho,23039
|
@@ -30,8 +30,8 @@ oarepo_runtime/services/records/mapping.py,sha256=y3oeToKEnaRYpMV3q2-2cXNzyzyL3X
|
|
30
30
|
oarepo_runtime/services/schema/__init__.py,sha256=jgAPI_uKC6Ug4KQWnwQVg3-aNaw-eHja323AUFo5ELo,351
|
31
31
|
oarepo_runtime/services/schema/i18n.py,sha256=9D1zOQaPKAnYzejB0vO-m2BJYnam0N0Lrq4jID7twfE,3174
|
32
32
|
oarepo_runtime/services/schema/i18n_ui.py,sha256=DbusphhGDeaobTt4nuwNgKZ6Houlu4Sv3SuMGkdjRRY,3582
|
33
|
-
oarepo_runtime-2.0.0.
|
34
|
-
oarepo_runtime-2.0.0.
|
35
|
-
oarepo_runtime-2.0.0.
|
36
|
-
oarepo_runtime-2.0.0.
|
37
|
-
oarepo_runtime-2.0.0.
|
33
|
+
oarepo_runtime-2.0.0.dev18.dist-info/METADATA,sha256=pC-YWi379OZ-3-kDzDg20ziCln3aaGO7ehf1auWoZNI,4495
|
34
|
+
oarepo_runtime-2.0.0.dev18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
35
|
+
oarepo_runtime-2.0.0.dev18.dist-info/entry_points.txt,sha256=rOfs8R1oXFN_dLH9zAZ6ydkvr83mDajegc6NBIRsCMQ,318
|
36
|
+
oarepo_runtime-2.0.0.dev18.dist-info/licenses/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
37
|
+
oarepo_runtime-2.0.0.dev18.dist-info/RECORD,,
|
File without changes
|
{oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/entry_points.txt
RENAMED
File without changes
|
{oarepo_runtime-2.0.0.dev16.dist-info → oarepo_runtime-2.0.0.dev18.dist-info}/licenses/LICENSE
RENAMED
File without changes
|