Skip to content

Commit

Permalink
Added fields to the parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
mesemus committed Jul 7, 2024
1 parent 80fad0b commit 5e05e1f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build-tests/thesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ record:
draft:
extra-code: |-2
test_options = "test"
draft-parent-record:
fields:
answer: "{{invenio_records.systemfields.constant.ConstantField}}('answer', 42)"
resource-config:
base-html-url: /ui/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from oarepo_model_builder.utils.python_name import module_to_path, parent_module
from oarepo_model_builder.validation.utils import ImportSchema

# TODO: consider moving all "parent" related record fields to "parent" section and profile


class DraftParentRecordSchema(ma.Schema):
class Meta:
Expand Down Expand Up @@ -37,6 +39,11 @@ class Meta:
)
skip = ma.fields.Boolean()
generate = ma.fields.Boolean()
fields = ma.fields.Dict(
attribute="fields",
data_key="fields",
metadata={"doc": "Extra fields to add to the class"},
)


class DraftParentRecordStateSchema(ma.Schema):
Expand Down Expand Up @@ -166,6 +173,7 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
"base-classes", ["invenio_drafts_resources.records.api.ParentRecord"]
)
draft_parent_record.setdefault("imports", [])
draft_parent_record.setdefault("fields", {})
draft_parent_record.setdefault("module", record_module)
draft_parent_record.setdefault("generate", True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ from invenio_records.systemfields import ConstantField
{{ vars.draft_parent_record|imports }}
{{ vars.draft_parent_record_metadata.class|generate_import }}

{% for extra_field_value in vars.draft_parent_record.fields.values() %}
{{ extra_field_value|code_imports }}
{% endfor %}


class {{ vars.draft_parent_record|class_header }}:
model_cls = {{ vars.draft_parent_record_metadata.class|base_name }}

{% for extra_field_name, extra_field_value in vars.draft_parent_record.fields.items() %}
{{ extra_field_name }} = {{ extra_field_value|extra_code }}
{% endfor %}
{% endif %}
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

OAREPO_VERSION=${OAREPO_VERSION:-11}
OAREPO_VERSION=${OAREPO_VERSION:-12}

BUILDER_VENV=".venv-builder"
if test -d $BUILDER_VENV ; then
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-drafts
version = 4.0.30
version = 4.0.31
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 5e05e1f

Please sign in to comment.