diff --git a/server/cp/output/formatter/jimi.py b/server/cp/output/formatter/jimi.py index b0ad47fa..52b683a5 100644 --- a/server/cp/output/formatter/jimi.py +++ b/server/cp/output/formatter/jimi.py @@ -7,6 +7,7 @@ import cp.ingest.parser.globenewswire as globenewswire import superdesk.etree as sd_etree +from typing import List, Union from num2words import num2words from collections import OrderedDict from celery.utils.functional import uniq @@ -105,6 +106,12 @@ def is_french(item) -> bool: return "fr" in item.get("language", "en") +def text_value(value: Union[str, List[str]]) -> str: + if not isinstance(value, list): + value = [value] + return ", ".join(value) + + class JimiFormatter(Formatter): ENCODING = "utf-8" @@ -513,12 +520,12 @@ def _format_picture_metadata(self, content, item): content.find("Source").text = item["original_source"] if extra.get(cp.ARCHIVE_SOURCE): - etree.SubElement(content, "ArchiveSources").text = extra[cp.ARCHIVE_SOURCE] + etree.SubElement(content, "ArchiveSources").text = text_value(extra[cp.ARCHIVE_SOURCE]) if extra.get(cp.PHOTOGRAPHER_CODE): - etree.SubElement(content, "BylineTitle").text = extra[ + etree.SubElement(content, "BylineTitle").text = text_value(extra[ cp.PHOTOGRAPHER_CODE - ].upper() + ]).upper() if item.get("copyrightnotice"): etree.SubElement(content, "Copyright").text = item["copyrightnotice"][:50] @@ -529,7 +536,7 @@ def _format_picture_metadata(self, content, item): ].replace(" ", " ") if extra.get(cp.CAPTION_WRITER): - etree.SubElement(content, "CaptionWriter").text = extra[cp.CAPTION_WRITER] + etree.SubElement(content, "CaptionWriter").text = text_value(extra[cp.CAPTION_WRITER]) if item.get("ednote"): etree.SubElement(content, "SpecialInstructions").text = item["ednote"] @@ -543,13 +550,13 @@ def _format_picture_metadata(self, content, item): ).text if extra.get(cp.INFOSOURCE): - etree.SubElement(content, "CustomField6").text = extra[cp.INFOSOURCE] + etree.SubElement(content, "CustomField6").text = text_value(extra[cp.INFOSOURCE]) if extra.get(cp.XMP_KEYWORDS): - etree.SubElement(content, "XmpKeywords").text = extra[cp.XMP_KEYWORDS] + etree.SubElement(content, "XmpKeywords").text = text_value(extra[cp.XMP_KEYWORDS]) if extra.get("container"): - etree.SubElement(content, "ContainerIDs").text = extra["container"] + etree.SubElement(content, "ContainerIDs").text = text_value(extra["container"]) else: self._format_refs(content, item) diff --git a/server/tests/output/formatter/jimi_test.py b/server/tests/output/formatter/jimi_test.py index 7c717a68..ca7ef432 100644 --- a/server/tests/output/formatter/jimi_test.py +++ b/server/tests/output/formatter/jimi_test.py @@ -248,6 +248,7 @@ def test_picture(self): "extra": { cp.FILENAME: "NY538", "photographer_code": "stf", + cp.CAPTION_WRITER: ["foo", "bar"], }, "subject": [ {"name": "Americas", "qcode": "A", "scheme": "photo_categories"}, @@ -287,6 +288,7 @@ def test_picture(self): self.assertEqual(updates["copyrightnotice"][:50], item.find("Copyright").text) self.assertEqual(updates["description_text"], item.find("EnglishCaption").text) self.assertEqual("2020-06-03T17:00:56", item.find("DateTaken").text) + self.assertEqual("foo, bar", item.find("CaptionWriter").text) self.assertEqual("media_id", item.find("FileName").text) self.assertEqual("media_id.jpg", item.find("ViewFile").text)