oarepo-runtime 1.5.53__py3-none-any.whl → 1.5.55__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,12 @@
1
+ import inspect
2
+ from collections import defaultdict
3
+ from typing import Type
4
+
5
+ from flask import current_app
1
6
  from invenio_accounts.models import User
7
+ from invenio_records import Record
2
8
 
9
+ from oarepo_runtime.services.custom_fields import CustomFieldsMixin, CustomFields, InlinedCustomFields
3
10
  from oarepo_runtime.services.generators import RecordOwners
4
11
 
5
12
  try:
@@ -51,3 +58,33 @@ class DateIssuedComponent(ServiceComponent):
51
58
  """Create a new record."""
52
59
  if "dateIssued" not in record["metadata"]:
53
60
  record["metadata"]["dateIssued"] = datetime.today().strftime("%Y-%m-%d")
61
+
62
+ class CFRegistry:
63
+ def __init__(self):
64
+ self.custom_field_names = defaultdict(list)
65
+
66
+ def lookup(self, record_type: Type[Record]):
67
+ if record_type not in self.custom_field_names:
68
+ for fld in inspect.getmembers(record_type, lambda x: isinstance(x, CustomFieldsMixin)):
69
+ self.custom_field_names[record_type].append(fld[1])
70
+ return self.custom_field_names[record_type]
71
+
72
+ cf_registry = CFRegistry()
73
+
74
+ class CustomFieldsComponent(ServiceComponent):
75
+ def create(self, identity, data=None, record=None, **kwargs):
76
+ """Create a new record."""
77
+ self._set_cf_to_record(record, data)
78
+
79
+ def update(self, identity, data=None, record=None, **kwargs):
80
+ """Update a record."""
81
+ self._set_cf_to_record(record, data)
82
+
83
+ def _set_cf_to_record(self, record, data):
84
+ for cf in cf_registry.lookup(type(record)):
85
+ if isinstance(cf, CustomFields):
86
+ setattr(record, cf.attr_name, data.get(cf.key, {}))
87
+ elif isinstance(cf, InlinedCustomFields):
88
+ config = current_app.config.get(cf.config_key, {})
89
+ for c in config:
90
+ record[c.name] =data.get(c.name)
@@ -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.53
3
+ Version: 1.5.55
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -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=zaZroTqzV5fz8yVAtRFLbbkTT9iD_dx9jFYANm3JIfI,3285
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.53.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
- oarepo_runtime-1.5.53.dist-info/METADATA,sha256=i-Y1DCOJ_st7MqMr6MKBOKa_pztMwkMrGHGNZ4xRbWg,4720
124
- oarepo_runtime-1.5.53.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
- oarepo_runtime-1.5.53.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
- oarepo_runtime-1.5.53.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
- oarepo_runtime-1.5.53.dist-info/RECORD,,
122
+ oarepo_runtime-1.5.55.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
+ oarepo_runtime-1.5.55.dist-info/METADATA,sha256=QkP7AUW4cdDHjbJ8UwGLkmUlp23l_q57oFfIr9B4FB0,4720
124
+ oarepo_runtime-1.5.55.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
+ oarepo_runtime-1.5.55.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
+ oarepo_runtime-1.5.55.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
+ oarepo_runtime-1.5.55.dist-info/RECORD,,