oarepo-runtime 1.2.19__py3-none-any.whl → 1.2.21__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/facets/base.py +9 -0
- oarepo_runtime/facets/date.py +10 -10
- oarepo_runtime/facets/enum.py +10 -0
- oarepo_runtime/relations/components.py +15 -0
- oarepo_runtime/relations/mapping.py +10 -0
- oarepo_runtime/relations/uow.py +7 -0
- oarepo_runtime/validation/__init__.py +2 -2
- oarepo_runtime/validation/dates.py +16 -2
- {oarepo_runtime-1.2.19.dist-info → oarepo_runtime-1.2.21.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.2.19.dist-info → oarepo_runtime-1.2.21.dist-info}/RECORD +14 -10
- {oarepo_runtime-1.2.19.dist-info → oarepo_runtime-1.2.21.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.2.19.dist-info → oarepo_runtime-1.2.21.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.2.19.dist-info → oarepo_runtime-1.2.21.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.2.19.dist-info → oarepo_runtime-1.2.21.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
from invenio_records_resources.services.records.facets import TermsFacet
|
2
|
+
|
3
|
+
|
4
|
+
class LabelledValuesTermsFacet(TermsFacet):
|
5
|
+
def __init__(self, *args, **kwargs):
|
6
|
+
super().__init__(*args, **{"value_labels": self.value_labels, **kwargs})
|
7
|
+
|
8
|
+
def value_labels(self, values):
|
9
|
+
return {val: val for val in values}
|
oarepo_runtime/facets/date.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
from invenio_records_resources.services.records.facets import TermsFacet
|
2
1
|
from oarepo_runtime.ui.marshmallow import (
|
3
2
|
LocalizedDate,
|
4
3
|
LocalizedTime,
|
@@ -7,14 +6,9 @@ from oarepo_runtime.ui.marshmallow import (
|
|
7
6
|
LocalizedEDTFInterval,
|
8
7
|
)
|
9
8
|
import re
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def __init__(self, *args, **kwargs):
|
14
|
-
super().__init__(*args, **{"value_labels": self.value_labels, **kwargs})
|
15
|
-
|
16
|
-
def value_labels(self, values):
|
17
|
-
return {val: val for val in values}
|
9
|
+
from .base import LabelledValuesTermsFacet
|
10
|
+
from invenio_search.engine import dsl
|
11
|
+
from invenio_records_resources.services.records.facets.facets import LabelledFacetMixin
|
18
12
|
|
19
13
|
|
20
14
|
class DateFacet(LabelledValuesTermsFacet):
|
@@ -39,7 +33,13 @@ class EDTFFacet(LabelledValuesTermsFacet):
|
|
39
33
|
}
|
40
34
|
|
41
35
|
|
42
|
-
class EDTFIntervalFacet(
|
36
|
+
class EDTFIntervalFacet(LabelledFacetMixin, dsl.DateHistogramFacet):
|
37
|
+
# auto_date_histogram
|
38
|
+
def __init__(self, *args, **kwargs):
|
39
|
+
if "interval" not in kwargs:
|
40
|
+
kwargs["interval"] = "year"
|
41
|
+
super().__init__(*args, **kwargs)
|
42
|
+
|
43
43
|
def value_labels(self, values):
|
44
44
|
return {
|
45
45
|
val: LocalizedEDTFInterval().format_value(convert_to_edtf(val))
|
@@ -0,0 +1,10 @@
|
|
1
|
+
from .base import LabelledValuesTermsFacet
|
2
|
+
from flask_babelex import lazy_gettext
|
3
|
+
|
4
|
+
|
5
|
+
class EnumTermsFacet(LabelledValuesTermsFacet):
|
6
|
+
def value_labels(self, values):
|
7
|
+
field = self._params["field"]
|
8
|
+
field_path = field.replace(".", "/")
|
9
|
+
field_enum = f"{field_path}.enum."
|
10
|
+
return {val: lazy_gettext(f"{field_enum}{val}") for val in values}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
from invenio_records_resources.services.records.components import ServiceComponent
|
2
|
+
|
3
|
+
from oarepo_runtime.relations import PIDRelation
|
4
|
+
from oarepo_runtime.relations.uow import CachingUnitOfWork
|
5
|
+
|
6
|
+
|
7
|
+
class CachingRelationsComponent(ServiceComponent):
|
8
|
+
def create(self, identity, *, record, **kwargs):
|
9
|
+
"""Create handler."""
|
10
|
+
# skutecny jmeno relations atributu
|
11
|
+
if isinstance(self.uow, CachingUnitOfWork) and hasattr(record, "relations"):
|
12
|
+
record.relations.set_cache(self.uow.cache)
|
13
|
+
def update(self, identity, *, record, **kwargs):
|
14
|
+
"""Update handler."""
|
15
|
+
self.create(identity, record=record, **kwargs)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
1
4
|
class RelationsMapping:
|
2
5
|
"""Helper class for managing relation fields."""
|
3
6
|
|
@@ -28,3 +31,10 @@ class RelationsMapping:
|
|
28
31
|
"""Clean dereferenced relation fields."""
|
29
32
|
for name in fields or self:
|
30
33
|
getattr(self, name).clean()
|
34
|
+
|
35
|
+
def set_cache(self, cache):
|
36
|
+
from oarepo_runtime.relations import PIDRelation
|
37
|
+
for key, fld in self._fields.items():
|
38
|
+
if isinstance(fld, PIDRelation):
|
39
|
+
fld.cache = cache
|
40
|
+
getattr(self, key).cache = cache
|
@@ -1,3 +1,3 @@
|
|
1
|
-
from .dates import validate_date, validate_datetime
|
1
|
+
from .dates import validate_date, validate_datetime, CachedMultilayerEDTFValidator
|
2
2
|
|
3
|
-
__all__ = ["validate_date", "validate_datetime"]
|
3
|
+
__all__ = ["validate_date", "validate_datetime", "CachedMultilayerEDTFValidator"]
|
@@ -1,6 +1,8 @@
|
|
1
|
+
import functools
|
2
|
+
import re
|
1
3
|
from datetime import datetime
|
2
|
-
|
3
4
|
from marshmallow.exceptions import ValidationError
|
5
|
+
from marshmallow_utils.fields.edtfdatestring import EDTFValidator
|
4
6
|
|
5
7
|
|
6
8
|
def validate_date(date_format):
|
@@ -14,7 +16,6 @@ def validate_date(date_format):
|
|
14
16
|
|
15
17
|
return validate
|
16
18
|
|
17
|
-
|
18
19
|
def validate_datetime(value):
|
19
20
|
try:
|
20
21
|
datetime.fromisoformat(value)
|
@@ -22,3 +23,16 @@ def validate_datetime(value):
|
|
22
23
|
raise ValidationError(
|
23
24
|
f"Invalid datetime format, expecting iso format, got {value}"
|
24
25
|
) from e
|
26
|
+
|
27
|
+
class CachedMultilayerEDTFValidator(EDTFValidator):
|
28
|
+
|
29
|
+
@functools.lru_cache(maxsize=1024)
|
30
|
+
def __call__(self, value):
|
31
|
+
if re.match(r"^\d{4}$", value):
|
32
|
+
return value
|
33
|
+
try:
|
34
|
+
datetime.strptime(value, "%Y-%m-%d")
|
35
|
+
return value
|
36
|
+
except:
|
37
|
+
return super().__call__(value)
|
38
|
+
|
@@ -31,7 +31,9 @@ oarepo_runtime/expansions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
31
31
|
oarepo_runtime/expansions/expandable_fields.py,sha256=7DWKFL6ml8J7zGI6wm9LO7Xd6R0LSylsuq4lyRumNHQ,745
|
32
32
|
oarepo_runtime/expansions/service.py,sha256=HaEy76XOhDf__sQ91hi-8iH1hthM9q07pRhOmyZyVrs,144
|
33
33
|
oarepo_runtime/facets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
|
-
oarepo_runtime/facets/
|
34
|
+
oarepo_runtime/facets/base.py,sha256=McdE4OxIVqmYj-Eqig-TVVMnSevi-jnR0cV89Kg-Ygs,322
|
35
|
+
oarepo_runtime/facets/date.py,sha256=-x0od8-WJrD8i8CPSFOZoKN1BJMppzTv5iuUO7MILjI,1663
|
36
|
+
oarepo_runtime/facets/enum.py,sha256=COH3yqL5X9ksNtwRIPS3LJqDTi29I0IPXnRQOS7yIFI,369
|
35
37
|
oarepo_runtime/facets/max_facet.py,sha256=XbkDBN5toidGC1mTw6-vMr0eyIoFZON8TQDRNWZOaz4,410
|
36
38
|
oarepo_runtime/facets/nested_facet.py,sha256=kNOR_YXoMjA1REhG_DidLdFG6ZqM40kp85yvatFCd3g,962
|
37
39
|
oarepo_runtime/i18n/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -40,19 +42,21 @@ oarepo_runtime/i18n/ui_schema.py,sha256=iJMVvdFmEXSoY8bjI-dZshDxwa-pnWxdZkdz4uWv
|
|
40
42
|
oarepo_runtime/i18n/validation.py,sha256=fyMTi2Rw-KiHv7c7HN61zGxRVa9sAjAEEkAL5wUyKNo,236
|
41
43
|
oarepo_runtime/relations/__init__.py,sha256=bDAgxl_LdKsqpGG3qluxAkQnn5u2ItJngnHQKkqzlkE,373
|
42
44
|
oarepo_runtime/relations/base.py,sha256=YLfZ_AKGv1uf-d22U01e7OwiBgW00lBmsPQbknhTFLI,8329
|
45
|
+
oarepo_runtime/relations/components.py,sha256=jgfVFxQspafiMWveWoN-8xPGdW7AdbYRJsmTyDq-Gww,650
|
43
46
|
oarepo_runtime/relations/internal.py,sha256=OTp8iJqyl80sWDk0Q0AK42l6UsxZDABspVU_GwWza9o,1556
|
44
47
|
oarepo_runtime/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfSdpmjK0wvOFsEM,848
|
45
|
-
oarepo_runtime/relations/mapping.py,sha256=
|
48
|
+
oarepo_runtime/relations/mapping.py,sha256=aafwCk75Avr6pPzlyUmBEmroFtJ_a5htKevuj1EBrkM,1279
|
46
49
|
oarepo_runtime/relations/pid_relation.py,sha256=OrF0Ihgua3tC7j5VBH116D5zHNHyodoeWux3ThLAZ3c,2063
|
50
|
+
oarepo_runtime/relations/uow.py,sha256=srF82vHNkbRegrwySTxMH4cUb9_WXZEiTsjIGKSzFH8,208
|
47
51
|
oarepo_runtime/tasks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
52
|
oarepo_runtime/tasks/datastreams.py,sha256=PLIPmKw1dwhVxtdJRENVsDWncOKEMIy2MuM7lwbc75E,11165
|
49
53
|
oarepo_runtime/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
50
54
|
oarepo_runtime/ui/marshmallow.py,sha256=6nusRVhzmlDU55tsLyaZL1TNeqOhrf0SVbEl_Bkbo_M,2601
|
51
|
-
oarepo_runtime/validation/__init__.py,sha256=
|
52
|
-
oarepo_runtime/validation/dates.py,sha256=
|
53
|
-
oarepo_runtime-1.2.
|
54
|
-
oarepo_runtime-1.2.
|
55
|
-
oarepo_runtime-1.2.
|
56
|
-
oarepo_runtime-1.2.
|
57
|
-
oarepo_runtime-1.2.
|
58
|
-
oarepo_runtime-1.2.
|
55
|
+
oarepo_runtime/validation/__init__.py,sha256=azOovv-cGpNDySLftlsJYQUIoqLOxUPKEduq4bN3btc,166
|
56
|
+
oarepo_runtime/validation/dates.py,sha256=SxjinCYX71wdGdz_UQXptUxeXpS77NvDh2cgV-kIUeM,1049
|
57
|
+
oarepo_runtime-1.2.21.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
58
|
+
oarepo_runtime-1.2.21.dist-info/METADATA,sha256=e2-sx4Sbl8n5LZ8UUXxy2rcOuU0DsGAFCHueK7OEoxo,2527
|
59
|
+
oarepo_runtime-1.2.21.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
60
|
+
oarepo_runtime-1.2.21.dist-info/entry_points.txt,sha256=C32W4eT-8OypMCfwOO5WREioVKSneDfY51D78Uvdbp0,231
|
61
|
+
oarepo_runtime-1.2.21.dist-info/top_level.txt,sha256=Vdo5ohKvEHniyXfcy3hv92nVSYIngDYGQtinWviujlw,15
|
62
|
+
oarepo_runtime-1.2.21.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|