oarepo-runtime 1.5.52__py3-none-any.whl → 1.5.54__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.
@@ -197,7 +197,7 @@ class InfoResource(Resource):
197
197
  return ret
198
198
 
199
199
  def call_components(self, method_name, **kwargs):
200
- for component in self.config.components:
200
+ for component in self.components:
201
201
  if hasattr(component, method_name):
202
202
  getattr(component, method_name)(**kwargs)
203
203
 
@@ -1,5 +1,11 @@
1
+ import inspect
2
+ from collections import defaultdict
3
+ from typing import Type
4
+
1
5
  from invenio_accounts.models import User
6
+ from invenio_records import Record
2
7
 
8
+ from oarepo_runtime.services.custom_fields import CustomFieldsMixin
3
9
  from oarepo_runtime.services.generators import RecordOwners
4
10
 
5
11
  try:
@@ -51,3 +57,26 @@ class DateIssuedComponent(ServiceComponent):
51
57
  """Create a new record."""
52
58
  if "dateIssued" not in record["metadata"]:
53
59
  record["metadata"]["dateIssued"] = datetime.today().strftime("%Y-%m-%d")
60
+
61
+ class CFRegistry:
62
+ def __init__(self):
63
+ self.custom_field_names = defaultdict(list)
64
+
65
+ def lookup(self, record_type: Type[Record]):
66
+ if record_type not in self.custom_field_names:
67
+ for fld in inspect.getmembers(record_type, lambda x: isinstance(x, CustomFieldsMixin)):
68
+ self.custom_field_names[record_type].append(fld[1])
69
+ return self.custom_field_names[record_type]
70
+
71
+ cf_registry = CFRegistry()
72
+
73
+ class CustomFieldsComponent(ServiceComponent):
74
+ def create(self, identity, data=None, record=None, **kwargs):
75
+ """Create a new record."""
76
+ for cf in cf_registry.lookup(type(record)):
77
+ setattr(record, cf.attr_name, data.get(cf.key, {}))
78
+
79
+ def update(self, identity, data=None, record=None, **kwargs):
80
+ """Update a record."""
81
+ for cf in cf_registry.lookup(type(record)):
82
+ setattr(record, cf.attr_name, data.get(cf.key, {}))
@@ -43,7 +43,16 @@ class CustomFields(CustomFieldsMixin, DictField):
43
43
 
44
44
 
45
45
  class InlinedCustomFields(CustomFieldsMixin, SystemField):
46
- pass
46
+
47
+ def __get__(self, record, owner=None):
48
+ """Getting the attribute value."""
49
+ if record is None:
50
+ return self
51
+ return self.get_dictkey(record)
52
+
53
+ def __set__(self, record, value):
54
+ """Setting a new value."""
55
+ self.set_dictkey(record, value)
47
56
 
48
57
 
49
58
  class InlinedCustomFieldsSchemaMixin:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.52
3
+ Version: 1.5.54
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -41,7 +41,7 @@ oarepo_runtime/datastreams/writers/validation_errors.py,sha256=wOCXdniR6so_4Expd
41
41
  oarepo_runtime/datastreams/writers/yaml.py,sha256=XchUJHQ58E2Mfgs8elImXbL38jFtI8Hfoye6yaR0gKI,1482
42
42
  oarepo_runtime/i18n/__init__.py,sha256=h0knW_HwiyIt5TBHfdGqN7_BBYfpz1Fw6zhVy0C28fM,111
43
43
  oarepo_runtime/info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
- oarepo_runtime/info/views.py,sha256=hgnHmNmT993zU_Id5Dsa8_u3hcUNdD6x3oXqnqWdM38,11117
44
+ oarepo_runtime/info/views.py,sha256=bH0FWS3SHpUmACeXOVwTIcSHa8qQvo19jMYEAEYhTu8,11110
45
45
  oarepo_runtime/records/__init__.py,sha256=3vzRsAPxl4d5QOnGyls-vUg4E6PunmR4ACObtacMAIQ,1038
46
46
  oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
47
47
  oarepo_runtime/records/dumpers/edtf_interval.py,sha256=YCShZAoqBQYaxVilEVotS-jXZsxxoXO67yu2urhkaMA,1198
@@ -68,14 +68,14 @@ oarepo_runtime/resources/__init__.py,sha256=v8BGrOTu_FjKzd0eozV7Q4GoGxyfybsL2cI-
68
68
  oarepo_runtime/resources/file_resource.py,sha256=Ta3bFce7l0xwqkkOMOEu9mxbB8BbKj5HUHRHmidhnl8,414
69
69
  oarepo_runtime/resources/localized_ui_json_serializer.py,sha256=3V9cJaG_e1PMXKVX_wKfBp1LmbeForwHyBNYdyha4uQ,1878
70
70
  oarepo_runtime/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
- oarepo_runtime/services/components.py,sha256=FkqyFe6-5HZKJDqglQ-Smm_AIsDZ-LyWcOr1u2yGu3k,1836
71
+ oarepo_runtime/services/components.py,sha256=qvzdzE4fdRNDm5Eei7WYssKNroQp9YnFP1HCOl1-Ijw,2942
72
72
  oarepo_runtime/services/generators.py,sha256=j87HitHA_w2awsz0C5IAAJ0qjg9JMtvdO3dvh6FQyfg,250
73
73
  oarepo_runtime/services/results.py,sha256=gPmQ7DzX4da5zuvqQE7u-AUn_Yvz-YHt8W8DaxPbQ-M,2706
74
74
  oarepo_runtime/services/search.py,sha256=9xGTN5Yg6eTdptQ9qjO_umbacf9ooMuHYGXWYfla4-M,6227
75
75
  oarepo_runtime/services/config/__init__.py,sha256=dtlD84pJ6xI77UF22IPrCOt7tHD3g5DAEDApUdjDVFE,406
76
76
  oarepo_runtime/services/config/permissions_presets.py,sha256=zApeA-2DYAlD--SzVz3vq_OFjq48Ko0pe08e4o2vxr4,6114
77
77
  oarepo_runtime/services/config/service.py,sha256=s-dVbGkLICpsce6jgu7b5kzYFz9opWjSQFDBgbIhKio,4002
78
- oarepo_runtime/services/custom_fields/__init__.py,sha256=xJ7XEyMJHPfIgX5JKpgpwh7SYc9Zee2dC5oC8cm99Qc,2282
78
+ oarepo_runtime/services/custom_fields/__init__.py,sha256=_gqMcA_I3rdEZcBtCuDjO4wdVCqFML5NzaccuPx5a3o,2565
79
79
  oarepo_runtime/services/custom_fields/mappings.py,sha256=tg9CAdxGOkd_n6RB5Z2_wSwo_A0wqEey8RMcZ79AHo0,6906
80
80
  oarepo_runtime/services/expansions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
81
81
  oarepo_runtime/services/expansions/expandable_fields.py,sha256=7DWKFL6ml8J7zGI6wm9LO7Xd6R0LSylsuq4lyRumNHQ,745
@@ -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.52.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
- oarepo_runtime-1.5.52.dist-info/METADATA,sha256=3Cs1djLllO6XGjBGXemmgjd5G-lQi6GIeLTMFzsHlg4,4720
124
- oarepo_runtime-1.5.52.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
- oarepo_runtime-1.5.52.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
- oarepo_runtime-1.5.52.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
- oarepo_runtime-1.5.52.dist-info/RECORD,,
122
+ oarepo_runtime-1.5.54.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
+ oarepo_runtime-1.5.54.dist-info/METADATA,sha256=LPFQp3spmVqEdbZ0A9VyGuftVZEqX7D4CqSRudES5D4,4720
124
+ oarepo_runtime-1.5.54.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
+ oarepo_runtime-1.5.54.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
+ oarepo_runtime-1.5.54.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
+ oarepo_runtime-1.5.54.dist-info/RECORD,,