Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planning: When starting to work on an Assignment prefill the article with the fields matching the language of the Coverage [SDESK-7061] #1859

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/planning/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]


def create_item_from_template(doc, extra_fields_to_override=None):
def create_item_from_template(doc, extra_fields_to_override=None, translations=None):
fields_to_override = deepcopy(TEMPLATE_FIELDS_TO_OVERRIDE)
if extra_fields_to_override is not None:
fields_to_override.extend(extra_fields_to_override)
Expand All @@ -38,6 +38,12 @@ def create_item_from_template(doc, extra_fields_to_override=None):
# and apply them if any found
updates = {key: val for key, val in doc.items() if key in fields_to_override}

# override translated values if any
translated_value = {
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
entry["field"]: entry["value"] for entry in translations or [] if entry["language"] == doc.get("language")
}
updates = {key: val for key, val in translated_value.items() if key in fields_to_override}
devketanpro marked this conversation as resolved.
Show resolved Hide resolved

if len(updates):
archive_service.patch(item_id, updates)

Expand Down
10 changes: 7 additions & 3 deletions server/planning/assignments/assignments_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_item_from_assignment(assignment, template=None):
:return dict: item
"""
item = {}
translations = {}
if not assignment:
return item

Expand Down Expand Up @@ -96,6 +97,9 @@ def get_item_from_assignment(assignment, template=None):
if not item.get("flags"):
item["flags"] = {}

if planning.get("translations"):
translations = planning.get("translations")

item["flags"]["marked_for_not_publication"] = (planning.get("flags") or {}).get(
"marked_for_not_publication"
) or False
Expand Down Expand Up @@ -133,7 +137,7 @@ def get_item_from_assignment(assignment, template=None):
if language:
item["language"] = language

return item
return item, translations


class AssignmentsContentService(Service):
Expand All @@ -147,7 +151,7 @@ def create(self, docs, **kwargs):
assignments_service = get_resource_service("assignments")
for doc in docs:
assignment = assignments_service.find_one(req=None, _id=doc.pop("assignment_id"))
item = get_item_from_assignment(assignment, doc.pop("template_name", None))
item, translations = get_item_from_assignment(assignment, doc.pop("template_name", None))
item[config.VERSION] = 1
item.setdefault("type", "text")
item["assignment_id"] = assignment[config.ID_FIELD]
Expand Down Expand Up @@ -177,7 +181,7 @@ def create(self, docs, **kwargs):
)
else:
# create content
item = create_item_from_template(item, FIELDS_TO_OVERRIDE)
item = create_item_from_template(item, FIELDS_TO_OVERRIDE, translations)

# create delivery references
get_resource_service("delivery").post(
Expand Down
Loading