oarepo-runtime 1.2.20__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.
@@ -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
@@ -0,0 +1,7 @@
1
+ from invenio_records_resources.services.uow import UnitOfWork
2
+
3
+
4
+ class CachingUnitOfWork(UnitOfWork):
5
+ def __init__(self, *args, **kwargs):
6
+ super().__init__(*args, **kwargs)
7
+ self.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
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.2.20
3
+ Version: 1.2.21
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -42,19 +42,21 @@ oarepo_runtime/i18n/ui_schema.py,sha256=iJMVvdFmEXSoY8bjI-dZshDxwa-pnWxdZkdz4uWv
42
42
  oarepo_runtime/i18n/validation.py,sha256=fyMTi2Rw-KiHv7c7HN61zGxRVa9sAjAEEkAL5wUyKNo,236
43
43
  oarepo_runtime/relations/__init__.py,sha256=bDAgxl_LdKsqpGG3qluxAkQnn5u2ItJngnHQKkqzlkE,373
44
44
  oarepo_runtime/relations/base.py,sha256=YLfZ_AKGv1uf-d22U01e7OwiBgW00lBmsPQbknhTFLI,8329
45
+ oarepo_runtime/relations/components.py,sha256=jgfVFxQspafiMWveWoN-8xPGdW7AdbYRJsmTyDq-Gww,650
45
46
  oarepo_runtime/relations/internal.py,sha256=OTp8iJqyl80sWDk0Q0AK42l6UsxZDABspVU_GwWza9o,1556
46
47
  oarepo_runtime/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfSdpmjK0wvOFsEM,848
47
- oarepo_runtime/relations/mapping.py,sha256=o7reFyfYoDAtj5Um-Me6GqiEIcG-tRRgN9gCe0sL4C0,1012
48
+ oarepo_runtime/relations/mapping.py,sha256=aafwCk75Avr6pPzlyUmBEmroFtJ_a5htKevuj1EBrkM,1279
48
49
  oarepo_runtime/relations/pid_relation.py,sha256=OrF0Ihgua3tC7j5VBH116D5zHNHyodoeWux3ThLAZ3c,2063
50
+ oarepo_runtime/relations/uow.py,sha256=srF82vHNkbRegrwySTxMH4cUb9_WXZEiTsjIGKSzFH8,208
49
51
  oarepo_runtime/tasks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
52
  oarepo_runtime/tasks/datastreams.py,sha256=PLIPmKw1dwhVxtdJRENVsDWncOKEMIy2MuM7lwbc75E,11165
51
53
  oarepo_runtime/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
54
  oarepo_runtime/ui/marshmallow.py,sha256=6nusRVhzmlDU55tsLyaZL1TNeqOhrf0SVbEl_Bkbo_M,2601
53
- oarepo_runtime/validation/__init__.py,sha256=ThKT-mxOdyzzR06wh-IkDuGaNRQtea4FLF_zX3WVk9Y,102
54
- oarepo_runtime/validation/dates.py,sha256=SBEyakvavsSPciHhLYHax2p98pnmuZCMGdgYLFBT6vY,622
55
- oarepo_runtime-1.2.20.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
56
- oarepo_runtime-1.2.20.dist-info/METADATA,sha256=6oOC4ok20sqJ3rThCIGjPrsM29Ik6eal0UeEnuWQdj4,2527
57
- oarepo_runtime-1.2.20.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
58
- oarepo_runtime-1.2.20.dist-info/entry_points.txt,sha256=C32W4eT-8OypMCfwOO5WREioVKSneDfY51D78Uvdbp0,231
59
- oarepo_runtime-1.2.20.dist-info/top_level.txt,sha256=Vdo5ohKvEHniyXfcy3hv92nVSYIngDYGQtinWviujlw,15
60
- oarepo_runtime-1.2.20.dist-info/RECORD,,
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,,