Skip to content

Commit

Permalink
Added primary service to invenio config (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
mesemus authored Aug 1, 2024
1 parent 81271be commit 2870117
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions oarepo_model_builder/invenio/templates/config.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{{ vars.service.class|imports }}
{{ vars.resource_config.class|imports }}
{{ vars.resource.class|imports }}
{{ vars.record.class|imports }}


{% if not vars.resource_config.skip %}
{{ vars.resource_config.config_key }} = {{ vars.resource_config.class|base_name }}
Expand All @@ -20,4 +22,8 @@
{{ vars.service.config_key }} = {{ vars.service.class|base_name }}
{% endif %}

OAREPO_PRIMARY_RECORD_SERVICE = {
{{ vars.record.class|base_name }}: "{{ vars.service_config.service_id }}"
}

{{ vars.config|extra_code }}
4 changes: 3 additions & 1 deletion oarepo_model_builder/invenio/templates/ext.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class {{ vars.ext|class_header }}:
if isinstance(app.config.get(identifier), list):
app.config[identifier] += getattr(config, identifier)
elif isinstance(app.config.get(identifier), dict):
app.config[identifier].update(getattr(config, identifier))
for k, v in getattr(config, identifier).items():
if k not in app.config[identifier]:
app.config[identifier][k] = v
else:
app.config.setdefault(identifier, getattr(config, identifier))

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-model-builder
version = 4.0.86
version = 4.0.87
description = A utility library that generates OARepo required data model files from a JSON specification file
authors = Miroslav Bauer <[email protected]>, Miroslav Simek <[email protected]>
readme = README.md
Expand Down
8 changes: 7 additions & 1 deletion tests/test_simple_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def init_config(self, app):
if isinstance(app.config.get(identifier), list):
app.config[identifier]+= getattr(config, identifier)
elif isinstance(app.config.get(identifier), dict):
app.config[identifier].update(getattr(config, identifier))
for k, v in getattr(config, identifier).items():
if k not in app.config[identifier]:
app.config[identifier][k]= v
else:
app.config.setdefault(identifier, getattr(config, identifier))
Expand Down Expand Up @@ -269,12 +271,16 @@ def test_config_builder():
from test.services.records.service import TestService
from test.resources.records.config import TestResourceConfig
from test.resources.records.resource import TestResource
from test.records.api import TestRecord
TEST_RECORD_RESOURCE_CONFIG = TestResourceConfig
TEST_RECORD_RESOURCE_CLASS = TestResource
TEST_RECORD_SERVICE_CONFIG = TestServiceConfig
TEST_RECORD_SERVICE_CLASS = TestService
OAREPO_PRIMARY_RECORD_SERVICE={
TestRecord: "test"
}
"""
)

Expand Down

0 comments on commit 2870117

Please sign in to comment.