Skip to content

Commit

Permalink
Merge pull request #230 from oarepo/profile-on-root
Browse files Browse the repository at this point in the history
Profile on root
  • Loading branch information
SilvyPuzzlewell authored Oct 12, 2023
2 parents 1fb3ff1 + 7c10740 commit 448b830
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})

Expand Down
4 changes: 4 additions & 0 deletions oarepo_model_builder/datatypes/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions oarepo_model_builder/datatypes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
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.53
version = 4.0.54
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

0 comments on commit 448b830

Please sign in to comment.