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

fix jimi formatter for pictures with multiple caption writers #185

Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 14 additions & 7 deletions server/cp/output/formatter/jimi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand All @@ -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"]
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions server/tests/output/formatter/jimi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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)
Expand Down
Loading