oarepo-runtime 1.5.20__py3-none-any.whl → 1.5.22__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,8 @@ import importlib_metadata
8
8
  import importlib_resources
9
9
  import marshmallow as ma
10
10
  from flask import current_app, request, url_for
11
+ from flask.ctx import RequestContext
12
+ from flask.globals import _cv_request
11
13
  from flask_resources import (
12
14
  Resource,
13
15
  ResourceConfig,
@@ -91,12 +93,13 @@ class InfoResource(Resource):
91
93
  model_data = json.loads(
92
94
  importlib_resources.files(package_name).joinpath(file_name).read_text()
93
95
  )
94
- model_data = model_data["model"]
95
- if model_data["type"] != "model":
96
+ model_data = model_data.get("model", {})
97
+ if model_data.get("type") != "model":
96
98
  continue
97
99
 
98
100
  service = self._get_service(model_data)
99
- if not service:
101
+ service_class = self._get_service_class(model_data)
102
+ if not service or type(service) != service_class:
100
103
  continue
101
104
 
102
105
  model_features = self._get_model_features(model_data)
@@ -271,6 +274,11 @@ class InfoResource(Resource):
271
274
  return service
272
275
 
273
276
 
277
+ def _get_service_class(self, model_data):
278
+ service_id = model_data["service"]["class"]
279
+ return obj_or_import_string(service_id)
280
+
281
+
274
282
  def create_wellknown_blueprint(app):
275
283
  """Create blueprint."""
276
284
  config_class = obj_or_import_string(
@@ -292,11 +300,23 @@ def get_package_version(package_name):
292
300
 
293
301
  def api_url_for(endpoint, _external=True, **values):
294
302
  """API url_for."""
303
+ try:
304
+ api_app = current_app.wsgi_app.mounts['/api']
305
+ except:
306
+ api_app = current_app
307
+
295
308
  site_api_url = current_app.config["SITE_API_URL"]
296
309
  site_url = current_app.config["SITE_UI_URL"]
297
- base_url = url_for(endpoint, **values, _external=_external)
298
- if base_url.startswith(site_api_url):
299
- return base_url
300
- if base_url.startswith(site_url):
301
- return base_url.replace(site_url, site_api_url)
302
- raise ValueError(f"URL {base_url} does not start with {site_url} or {site_api_url}")
310
+ current_request_context = _cv_request.get()
311
+ try:
312
+ new_context = RequestContext(app=api_app,
313
+ environ=request.environ)
314
+ _cv_request.set(new_context)
315
+ base_url = api_app.url_for(endpoint, **values, _external=_external)
316
+ if base_url.startswith(site_api_url):
317
+ return base_url
318
+ if base_url.startswith(site_url):
319
+ return base_url.replace(site_url, site_api_url)
320
+ raise ValueError(f"URL {base_url} does not start with {site_url} or {site_api_url}")
321
+ finally:
322
+ _cv_request.set(current_request_context)
@@ -1,3 +1,5 @@
1
+ from inspect import isfunction
2
+
1
3
  from invenio_records.dictutils import dict_set
2
4
  from invenio_records.systemfields import SystemField
3
5
  from sqlalchemy.orm.exc import NoResultFound
@@ -34,6 +36,8 @@ class HasDraftCheckField(CustomFieldsMixin, SystemField):
34
36
  return False
35
37
 
36
38
  try:
39
+ if isfunction(self.draft_cls):
40
+ self.draft_cls = self.draft_cls()
37
41
  self.draft_cls.get_record(record.id)
38
42
  return True
39
43
  except NoResultFound:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.20
3
+ Version: 1.5.22
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=G4PJ_kQlPDiBW6ntjQZ-O4qHQgkJWAXsNLUuOBcglNM,402
43
43
  oarepo_runtime/info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
- oarepo_runtime/info/views.py,sha256=W1aa6c6ZYABcjSgH3DfjadHrFHqn2Myc1XarkEvWxU0,10399
44
+ oarepo_runtime/info/views.py,sha256=jtI2JJBdApuT5ZIxU2kskJBz6GpJVTgUGrM8EMNIiAk,11137
45
45
  oarepo_runtime/records/__init__.py,sha256=Bxm2XNtB9j6iOAKGSVsjXTKIZS-iXKPzakCqyNkEix8,432
46
46
  oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
47
47
  oarepo_runtime/records/dumpers/edtf_interval.py,sha256=YCShZAoqBQYaxVilEVotS-jXZsxxoXO67yu2urhkaMA,1198
@@ -57,7 +57,7 @@ oarepo_runtime/records/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfS
57
57
  oarepo_runtime/records/relations/pid_relation.py,sha256=zJjSf_ocFBViYsOuMMZLbQZpNZeKiOK33dPD4tk74Qo,2786
58
58
  oarepo_runtime/records/systemfields/__init__.py,sha256=SPaMWM6t-azz6gZLUKvvXbOyE2_-LW6i_szQk8nhbAc,455
59
59
  oarepo_runtime/records/systemfields/featured_file.py,sha256=MbSaYR130_o5S9gEOblnChq-PVK4xGPGpSCrzwG3cwc,1720
60
- oarepo_runtime/records/systemfields/has_draftcheck.py,sha256=3XLRsZJWRpT4BFF1HTg6C27ECVmIcZ4RrdGzYC8S7v0,1518
60
+ oarepo_runtime/records/systemfields/has_draftcheck.py,sha256=4JkMEefPLpqtPtlTgK3UT0KzTRgyw5_Qtkss2qcz5xk,1643
61
61
  oarepo_runtime/records/systemfields/icu.py,sha256=tAwplzy9y7C9Dm7HqcGZsDu2AKqVGXhCbKLsFlgVWg8,5921
62
62
  oarepo_runtime/records/systemfields/mapping.py,sha256=tXOK_jkdY1pOUO7_VfChfDNB8UTi21GUXaidpugTnO8,1017
63
63
  oarepo_runtime/records/systemfields/owner.py,sha256=46-EKkGq77FYQgZFvUhWxvaVlu9KbRWg5nveZL4cAP4,3633
@@ -114,9 +114,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
114
114
  oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
115
115
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
116
116
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
117
- oarepo_runtime-1.5.20.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
118
- oarepo_runtime-1.5.20.dist-info/METADATA,sha256=KmFlgRvnRSdxUggzIcCQgMlWcgUiWpGhSd-s0UiqlbU,4680
119
- oarepo_runtime-1.5.20.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
120
- oarepo_runtime-1.5.20.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
121
- oarepo_runtime-1.5.20.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
122
- oarepo_runtime-1.5.20.dist-info/RECORD,,
117
+ oarepo_runtime-1.5.22.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
118
+ oarepo_runtime-1.5.22.dist-info/METADATA,sha256=Pj8uJfDhVkrJiFU2SsjLs0lBrriYCG-qx7uEVnVm1mQ,4680
119
+ oarepo_runtime-1.5.22.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
120
+ oarepo_runtime-1.5.22.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
121
+ oarepo_runtime-1.5.22.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
122
+ oarepo_runtime-1.5.22.dist-info/RECORD,,