From 7c1896e155e51892541fa70de978ade3f56fc04e Mon Sep 17 00:00:00 2001 From: devketanpro Date: Wed, 8 Nov 2023 18:42:49 +0530 Subject: [PATCH 1/6] update assignment preview to support multilngual fields data --- server/planning/planning/planning.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 3204a9ec0..1414b1160 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -456,6 +456,7 @@ def remove_coverage_entity(self, coverage_entity, original_planning, entity_type self._create_update_assignment(original_planning, {}, updated_coverage_entity, coverage_entity) def add_coverages(self, updates, original): + # print("sdjksndfndsjksdjndsjdsjdsndjsjsdjsdfjn\n\n\n\n\n\n\n\n", original) planning_date = original.get("planning_date") or updates.get("planning_date") for coverage in updates.get("coverages") or []: coverage_id = coverage.get("coverage_id", "") @@ -474,6 +475,7 @@ def add_coverages(self, updates, original): set_original_creator(coverage) self.set_coverage_active(coverage, updates) self.set_slugline_from_xmp(coverage, None) + # print("sdjksndfndsjksdjndsjdsjdsndjsjsdjsdfjn\n\n\n\n\n\n\n\n", original) self._create_update_assignment(original, updates, coverage) self.add_scheduled_updates(updates, original, coverage) @@ -735,6 +737,21 @@ def _create_update_assignment( coverage_status = updates.get("workflow_status", original.get("workflow_status")) is_coverage_draft = coverage_status == WORKFLOW_STATE.DRAFT + translations = planning.get("translations") + if translations is not None: + translated_value = { + entry["field"]: entry["value"] + for entry in translations or [] + if entry["language"] == doc.get("planning", {}).get("language") + } + doc["planning"].update( + { + key: val + for key, val in translated_value.items() + if key in ("ednote", "description_text", "headline", "slugline", "authors", "internal_note") + } + ) + if not assigned_to.get("assignment_id") and (assigned_to.get("user") or assigned_to.get("desk")): # Creating a new assignment assign_state = ASSIGNMENT_WORKFLOW_STATE.DRAFT if is_coverage_draft else ASSIGNMENT_WORKFLOW_STATE.ASSIGNED @@ -743,6 +760,9 @@ def _create_update_assignment( if assigned_to.get("state") and assigned_to["state"] != ASSIGNMENT_WORKFLOW_STATE.DRAFT: assign_state = assigned_to.get("state") + if translated_value.get("name") and not "headline" in doc["planning"]: + doc["planning"]["headline"] = translated_value.get("name") + assignment = { "assigned_to": { "user": assigned_to.get("user"), @@ -756,6 +776,8 @@ def _create_update_assignment( "priority": assigned_to.get("priority", DEFAULT_ASSIGNMENT_PRIORITY), "description_text": planning.get("description_text"), } + if translated_value.get("name") and assignment.get("name") != translated_value.get("name"): + assignment["name"] = translated_value.get("name") if doc.get("scheduled_update_id"): assignment["scheduled_update_id"] = doc["scheduled_update_id"] @@ -846,7 +868,7 @@ def _create_update_assignment( # If the Planning name has been changed if planning_original.get("name") != planning_updates.get("name"): - assignment["name"] = planning["name"] + assignment["name"] = planning["name"] if not translated_value.get("name") else translated_value["name"] # If there has been a change in the planning internal note then notify the assigned users/desk if planning_updates.get("internal_note") and planning_original.get("internal_note") != planning_updates.get( From 07797ec335ea011bd5698183f4db30d9873f02b0 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Wed, 8 Nov 2023 18:44:34 +0530 Subject: [PATCH 2/6] remove unwanted print --- server/planning/planning/planning.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 1414b1160..6b5475fe0 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -456,7 +456,6 @@ def remove_coverage_entity(self, coverage_entity, original_planning, entity_type self._create_update_assignment(original_planning, {}, updated_coverage_entity, coverage_entity) def add_coverages(self, updates, original): - # print("sdjksndfndsjksdjndsjdsjdsndjsjsdjsdfjn\n\n\n\n\n\n\n\n", original) planning_date = original.get("planning_date") or updates.get("planning_date") for coverage in updates.get("coverages") or []: coverage_id = coverage.get("coverage_id", "") @@ -475,7 +474,6 @@ def add_coverages(self, updates, original): set_original_creator(coverage) self.set_coverage_active(coverage, updates) self.set_slugline_from_xmp(coverage, None) - # print("sdjksndfndsjksdjndsjdsjdsndjsjsdjsdfjn\n\n\n\n\n\n\n\n", original) self._create_update_assignment(original, updates, coverage) self.add_scheduled_updates(updates, original, coverage) From 7a0b6896b5865b2c7aad58637456c0e53f106281 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Wed, 8 Nov 2023 19:30:22 +0530 Subject: [PATCH 3/6] minor change --- server/planning/planning/planning.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 6b5475fe0..7b494a8fd 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -736,12 +736,15 @@ def _create_update_assignment( is_coverage_draft = coverage_status == WORKFLOW_STATE.DRAFT translations = planning.get("translations") + translated_value = {} if translations is not None: - translated_value = { - entry["field"]: entry["value"] - for entry in translations or [] - if entry["language"] == doc.get("planning", {}).get("language") - } + translated_value.update( + { + entry["field"]: entry["value"] + for entry in translations or [] + if entry["language"] == doc.get("planning", {}).get("language") + } + ) doc["planning"].update( { key: val From 53d86d2200149b8a98bfaebc88bb427d19e74dd1 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Wed, 8 Nov 2023 19:32:18 +0530 Subject: [PATCH 4/6] fix flake8 --- server/planning/planning/planning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 7b494a8fd..997665183 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -761,7 +761,7 @@ def _create_update_assignment( if assigned_to.get("state") and assigned_to["state"] != ASSIGNMENT_WORKFLOW_STATE.DRAFT: assign_state = assigned_to.get("state") - if translated_value.get("name") and not "headline" in doc["planning"]: + if translated_value.get("name") and "headline" not in doc["planning"]: doc["planning"]["headline"] = translated_value.get("name") assignment = { From 3a8dee79b590a6cc24f9b6a69c005868895b6d28 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Thu, 9 Nov 2023 01:02:09 +0530 Subject: [PATCH 5/6] handle translated name and headline both --- server/planning/planning/planning.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 997665183..6793ed810 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -745,6 +745,9 @@ def _create_update_assignment( if entry["language"] == doc.get("planning", {}).get("language") } ) + + translated_name = translated_value.get("name", translated_value.get("headline")) + doc["planning"].update( { key: val @@ -761,8 +764,8 @@ def _create_update_assignment( if assigned_to.get("state") and assigned_to["state"] != ASSIGNMENT_WORKFLOW_STATE.DRAFT: assign_state = assigned_to.get("state") - if translated_value.get("name") and "headline" not in doc["planning"]: - doc["planning"]["headline"] = translated_value.get("name") + if translated_value and translated_name and "headline" not in doc["planning"]: + doc["planning"]["headline"] = translated_name assignment = { "assigned_to": { @@ -777,8 +780,8 @@ def _create_update_assignment( "priority": assigned_to.get("priority", DEFAULT_ASSIGNMENT_PRIORITY), "description_text": planning.get("description_text"), } - if translated_value.get("name") and assignment.get("name") != translated_value.get("name"): - assignment["name"] = translated_value.get("name") + if translated_value and translated_name and assignment.get("name") != translated_value.get("name"): + assignment["name"] = translated_name if doc.get("scheduled_update_id"): assignment["scheduled_update_id"] = doc["scheduled_update_id"] @@ -869,7 +872,7 @@ def _create_update_assignment( # If the Planning name has been changed if planning_original.get("name") != planning_updates.get("name"): - assignment["name"] = planning["name"] if not translated_value.get("name") else translated_value["name"] + assignment["name"] = planning["name"] if not translated_value and translated_name else translated_name # If there has been a change in the planning internal note then notify the assigned users/desk if planning_updates.get("internal_note") and planning_original.get("internal_note") != planning_updates.get( From 3793ea12f5040d904f0f47cb3f945166ef092551 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Thu, 9 Nov 2023 09:21:24 +0530 Subject: [PATCH 6/6] refactore code --- server/planning/planning/planning.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 6793ed810..e3cfb50c9 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -737,6 +737,7 @@ def _create_update_assignment( translations = planning.get("translations") translated_value = {} + translated_name = "" if translations is not None: translated_value.update( {