Skip to content

Commit

Permalink
Merge pull request #21 from oarepo/fixes
Browse files Browse the repository at this point in the history
dict parent additional fields and owners field requirements
  • Loading branch information
SilvyPuzzlewell authored Mar 13, 2024
2 parents 571dd70 + 77508db commit c6adc6d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ class ModelSchema(ma.Schema):
# metadata={"doc": "Service config settings"},
)

def process_mb_invenio_drafts_parent_additional_fields(
self, datatype, section, **kwargs
):
obj = section.config.setdefault("additional-fields", {})
obj |= {"owners": "{{oarepo_runtime.records.systemfields.owner.OwnersField}}()"}

def before_model_prepare(self, datatype, *, context, **kwargs):
record_module = datatype.definition["record"]["module"]
metadata_module = datatype.definition["record-metadata"]["module"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ModelSchema(ma.Schema):
data_key="parent-record-marshmallow",
)

def process_mb_invenio_drafts_parent_marshmallow(self, datatype, section, **kwargs):
obj = section.config.setdefault("additional-fields", {})
obj |= {"owners": "ma_fields.List(ma_fields.Dict(), load_only=True)"}

def before_model_prepare(self, datatype, *, context, **kwargs):
marshmallow = set_default(datatype, "parent-record-marshmallow", {})
m_module = marshmallow.setdefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
)

super().before_model_prepare(datatype, context=context, **kwargs)
record_service_config.setdefault("components", []).append(
"{{oarepo_runtime.services.components.OwnersComponent}}"
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% if "additional-fields" in vars %}
{{ vars.additional_fields|imports }}
{% for field in vars.additional_fields.values() %}
{{ field|code_imports }}
{% endfor %}

class {{ vars.draft_parent_record|class_header }}:
{% for field in vars.additional_fields.fields %}
{{ field }}
{% endfor %}
{% for field_name, field in vars.additional_fields.items() %}
{{ field_name }} = {{ field|extra_code }}
{% endfor %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{{ vars.parent_record_marshmallow|generate_import }}
{% if "additional-fields" in vars %}
{{ vars.additional_fields|imports }}
{% for field in vars.additional_fields.values() %}
{{ field|code_imports }}
{% endfor %}
{% endif %}
class {{ vars.parent_record_marshmallow|class_header }}:
""""""
{% if "additional-fields" in vars %}
{% for field in vars.additional_fields.fields %}
{{ field }}
{% for field_name, field in vars.additional_fields.items() %}
{{ field_name }} = {{ field|extra_code }}
{% endfor %}
{% endif %}
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ pip install -U setuptools pip wheel
pip install "oarepo[tests]==${OAREPO_VERSION}.*"

pip install "./build-tests/${MODEL}[tests]"
pytest build-tests/$MODEL/tests
# pytest build-tests/$MODEL/tests

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-drafts
version = 4.0.19
version = 4.0.20
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit c6adc6d

Please sign in to comment.