From 2ee57d72455cd2d0c05bf1d7d0e2dc52fdf91b0e Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Thu, 12 Oct 2023 09:45:02 +0200 Subject: [PATCH 1/2] profile on datatype root --- .../datatypes/components/model/ext_resource.py | 5 ++--- oarepo_model_builder/datatypes/datatypes.py | 4 ++++ oarepo_model_builder/datatypes/model.py | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/oarepo_model_builder/datatypes/components/model/ext_resource.py b/oarepo_model_builder/datatypes/components/model/ext_resource.py index 9d011639..b90a47c5 100644 --- a/oarepo_model_builder/datatypes/components/model/ext_resource.py +++ b/oarepo_model_builder/datatypes/components/model/ext_resource.py @@ -23,14 +23,13 @@ class ModelSchema(ma.Schema): ) def process_ext_resource(self, datatype, section, **kwargs): - if self.is_record_profile: + if datatype.profile == "record": cfg = section.config cfg["ext-service-name"] = "service_records" cfg["ext-resource-name"] = "resource_records" def before_model_prepare(self, datatype, *, context, **kwargs): - self.is_record_profile = context["profile"] == "record" - if not self.is_record_profile: + if not datatype.profile == "record": return ext = set_default(datatype, "ext-resource", {}) diff --git a/oarepo_model_builder/datatypes/datatypes.py b/oarepo_model_builder/datatypes/datatypes.py index 706533fa..7e7ece03 100644 --- a/oarepo_model_builder/datatypes/datatypes.py +++ b/oarepo_model_builder/datatypes/datatypes.py @@ -225,6 +225,10 @@ def stack(self): p = p.parent return tuple(reversed(ret)) + @property + def root(self): + return self.stack[0] + class DataType(AbstractDataType): model_type = None diff --git a/oarepo_model_builder/datatypes/model.py b/oarepo_model_builder/datatypes/model.py index 6f1d5bd9..0fae79a9 100644 --- a/oarepo_model_builder/datatypes/model.py +++ b/oarepo_model_builder/datatypes/model.py @@ -71,6 +71,8 @@ def links(self): } def prepare(self, context): + if "profile" in context: + self.profile = context["profile"] datatypes.call_components( datatype=self, method="before_model_prepare", context=context ) From 7c10740a481c44096503004197137375963e04b9 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Thu, 12 Oct 2023 09:45:32 +0200 Subject: [PATCH 2/2] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 47f696ba..dc1c02aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-model-builder -version = 4.0.53 +version = 4.0.54 description = A utility library that generates OARepo required data model files from a JSON specification file authors = Miroslav Bauer , Miroslav Simek readme = README.md