diff --git a/server/planning/archive.py b/server/planning/archive.py index 586462497..a430757c5 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,10 @@ 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 = {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} + 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(