Skip to content

Commit

Permalink
Merge pull request #43 from oarepo/miroslavsimek/be-574-regression-fi…
Browse files Browse the repository at this point in the history
…elds-from-published-record-not-added-to-draft

fix: published fields not propagated to draft record
  • Loading branch information
Alzpeta authored Dec 2, 2024
2 parents c561167 + 6ca24d1 commit fb85c13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
12 changes: 0 additions & 12 deletions build-tests/thesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ record:
qualified: thesis
permissions:
presets: [ 'everyone' ]
# package: thesis
# schema-server: 'local://'
use:
- invenio
draft:
Expand All @@ -26,13 +24,3 @@ record:
profiles:
- record
- draft
#files:
# use:
# - invenio_files
# properties:
# metadata:
# properties:
# title:
# type: fulltext
# package: thesis
# schema-server: 'local://'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from oarepo_model_builder.datatypes import ModelDataType
from oarepo_model_builder.datatypes import DataType, ModelDataType
from oarepo_model_builder.datatypes.components import RecordModelComponent
from oarepo_model_builder.datatypes.components.model.utils import set_default
from oarepo_model_builder.datatypes import DataType


class DraftRecordModelComponent(RecordModelComponent):
eligible_datatypes = [ModelDataType]
Expand All @@ -25,7 +25,25 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
extra_code = datatype.model.get("extra-code", "")
record.setdefault("extra-code", extra_code)
is_record_preset = record.get("class", None)
record.setdefault("fields", published_record_datatype.definition["record"]["fields"]) #if fields defined on draft, still propagate the record ones?

# get draft record fields
draft_record_fields = record.setdefault("fields", {})

# for each published field, add it to the draft record fields if it is not already there
published_record_fields = published_record_datatype.definition["record"][
"fields"
]
for (
published_field_name,
published_field,
) in published_record_fields.items():
if published_field_name not in draft_record_fields:
draft_record_fields[published_field_name] = published_field

# null value is used to remove the field from the draft record
# even if it is present in the published record
draft_record_fields = {k: v for k, v in draft_record_fields.items() if v}

super().before_model_prepare(datatype, context=context, **kwargs)
if not is_record_preset and record["class"][-6:] == "Record":
record["class"] = record["class"][:-6]
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.34
version = 4.0.35
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit fb85c13

Please sign in to comment.