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

pls adapt the NINJS outputformatter to provide better references for all renditions [SDCP-723] #2489

Merged
merged 10 commits into from
Nov 16, 2023
1 change: 1 addition & 0 deletions superdesk/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def local_to_utc_hour(hour):
},
}

NINJS_COMMON_RENDITIONS = list(RENDITIONS["picture"].keys())

#: BCRYPT work factor
BCRYPT_GENSALT_WORK_FACTOR = 12
Expand Down
40 changes: 38 additions & 2 deletions superdesk/io/feed_parsers/ninjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def _transform_from_ninjs(self, ninjs):
associated_item["versioncreated"] = self.datetime(associated_item["versioncreated"])
item["associations"][key] = deepcopy(associated_item)

if ninjs.get("renditions", {}).get("baseImage"):
item["renditions"] = {"baseImage": {"href": ninjs.get("renditions", {}).get("original", {}).get("href")}}
if ninjs.get("renditions"):
item["renditions"] = self.parse_renditions(ninjs["renditions"])

if ninjs.get("located"):
item["dateline"] = {"located": {"city": ninjs.get("located")}}
Expand All @@ -146,6 +146,42 @@ def _transform_from_ninjs(self, ninjs):

return item

def parse_renditions(self, renditions):
rend = []
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
for rendition_name, rendition_data in renditions.items():
parsed_rendition = {}

# Parse href
href = rendition_data.get("href", "")
if isinstance(href, str) and href:
parsed_rendition["href"] = href

# Parse width and height
width = rendition_data.get("width")
height = rendition_data.get("height")
if isinstance(width, int) and isinstance(height, int):
parsed_rendition["width"] = width
parsed_rendition["height"] = height

# Parse mimetype
mimetype = rendition_data.get("mimetype", "")
if isinstance(mimetype, str) and mimetype:
parsed_rendition["mimetype"] = mimetype

# Parse poi
poi = rendition_data.get("poi", {})
if isinstance(poi, dict) and "x" in poi and "y" in poi:
parsed_rendition["poi"] = {"x": poi["x"], "y": poi["y"]}

# Parse media
media = rendition_data.get("media", "")
if isinstance(media, str) and media:
parsed_rendition["media"] = media

if parsed_rendition:
rend.append({rendition_name: parsed_rendition})
return rend

def _format_qcodes(self, items):
subjects = []
for item in items:
Expand Down
2 changes: 1 addition & 1 deletion superdesk/publish/formatters/ninjs_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(self):
self.format_type = "ninjs"
self.can_preview = True
self.can_export = True
self.internal_renditions = ["original"]
self.internal_renditions = app.config.get("NINJS_COMMON_RENDITIONS", []) + ["original"]

def format(self, article, subscriber, codes=None):
try:
Expand Down
Loading