From 7743bf28abf62de330838d46036f350997da4a92 Mon Sep 17 00:00:00 2001 From: Ketan <73937490+devketanpro@users.noreply.github.com> Date: Mon, 9 Oct 2023 15:16:02 +0530 Subject: [PATCH] Planning: When starting to work on an Assignment prefill the article with the fields matching the language of the Coverage [SDESK-7061] (#1859) * Planning: When starting to work on an Assignment prefill the article with the fields matching the language of the Coverage [SDESK-7061] * fix black * addressed comment --- server/planning/archive.py | 8 +++++++- server/planning/assignments/assignments_content.py | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/planning/archive.py b/server/planning/archive.py index 586462497..bd0ec914d 100644 --- a/server/planning/archive.py +++ b/server/planning/archive.py @@ -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) @@ -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} + if translations is not None: + translated_value = { + entry["field"]: entry["value"] for entry in translations or [] if entry["language"] == doc.get("language") + } + updates.update({key: val for key, val in translated_value.items() if key in fields_to_override}) + if len(updates): archive_service.patch(item_id, updates) diff --git a/server/planning/assignments/assignments_content.py b/server/planning/assignments/assignments_content.py index 45a204425..16ec182fc 100644 --- a/server/planning/assignments/assignments_content.py +++ b/server/planning/assignments/assignments_content.py @@ -54,6 +54,7 @@ def get_item_from_assignment(assignment, template=None): :return dict: item """ item = {} + translations = {} if not assignment: return item @@ -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 @@ -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): @@ -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] @@ -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(