Skip to content

Commit

Permalink
fix lint vol. 2
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Feb 8, 2024
1 parent de8de88 commit dc44579
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
2 changes: 0 additions & 2 deletions server/cp/output/formatter/cp_ninjs_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
def format_cv_item(item, language):
"""Format item from controlled vocabulary for output."""
if item.get("scheme") == "subject":

return filter_empty_vals(
{
"code": item.get("qcode"),
Expand All @@ -17,7 +16,6 @@ def format_cv_item(item, language):
}
)
else:

return filter_empty_vals(
{
"code": item.get("qcode"),
Expand Down
67 changes: 42 additions & 25 deletions server/cp/output/formatter/jimi.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def text_value(value: Union[str, List[str]]) -> str:


class JimiFormatter(Formatter):

ENCODING = "utf-8"

type = "jimi"
Expand Down Expand Up @@ -188,7 +187,9 @@ def _format_item(self, root, item, pub_seq_num, service, services) -> None:
if root.find("PscCodes") is None:
etree.SubElement(root, "PscCodes").text = "Online"
elif service:
etree.SubElement(root, "Services").text = "Écrit" if is_french(item) else "Print"
etree.SubElement(root, "Services").text = (
"Écrit" if is_french(item) else "Print"
)
etree.SubElement(root, "PscCodes").text = service
else:
self._format_subject_code(root, item, "PscCodes", cp.DESTINATIONS)
Expand Down Expand Up @@ -262,9 +263,7 @@ def _format_item(self, root, item, pub_seq_num, service, services) -> None:
item.get("abstract")
)
etree.SubElement(content, "ContentText").text = self._format_html(content_html)
etree.SubElement(content, "Language").text = (
"2" if is_french(item) else "1"
)
etree.SubElement(content, "Language").text = "2" if is_french(item) else "1"

if item["type"] == "text" and content_html:
content.find("DirectoryText").text = format_maxlength(
Expand Down Expand Up @@ -307,7 +306,9 @@ def _format_item(self, root, item, pub_seq_num, service, services) -> None:

def get_item_id(self, item):
if item.get("family_id"):
ingest_item = superdesk.get_resource_service("ingest").find_one(req=None, _id=item["family_id"])
ingest_item = superdesk.get_resource_service("ingest").find_one(
req=None, _id=item["family_id"]
)
if ingest_item and ingest_item.get("unique_id"):
return ingest_item["unique_id"]
return item["unique_id"]
Expand Down Expand Up @@ -520,12 +521,14 @@ 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 = text_value(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 = text_value(extra[
cp.PHOTOGRAPHER_CODE
]).upper()
etree.SubElement(content, "BylineTitle").text = text_value(
extra[cp.PHOTOGRAPHER_CODE]
).upper()

if item.get("copyrightnotice"):
etree.SubElement(content, "Copyright").text = item["copyrightnotice"][:50]
Expand All @@ -536,7 +539,9 @@ def _format_picture_metadata(self, content, item):
].replace(" ", " ")

if extra.get(cp.CAPTION_WRITER):
etree.SubElement(content, "CaptionWriter").text = text_value(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 @@ -550,13 +555,19 @@ def _format_picture_metadata(self, content, item):
).text

if extra.get(cp.INFOSOURCE):
etree.SubElement(content, "CustomField6").text = text_value(extra[cp.INFOSOURCE])
etree.SubElement(content, "CustomField6").text = text_value(
extra[cp.INFOSOURCE]
)

if extra.get(cp.XMP_KEYWORDS):
etree.SubElement(content, "XmpKeywords").text = text_value(extra[cp.XMP_KEYWORDS])
etree.SubElement(content, "XmpKeywords").text = text_value(
extra[cp.XMP_KEYWORDS]
)

if extra.get("container"):
etree.SubElement(content, "ContainerIDs").text = text_value(extra["container"])
etree.SubElement(content, "ContainerIDs").text = text_value(
extra["container"]
)
else:
self._format_refs(content, item)

Expand All @@ -565,17 +576,19 @@ def _format_refs(self, content, item):
refs = set(
[
slug(self._get_original_item(ref))
for ref in superdesk.get_resource_service("news").search({
"query": {
"bool": {
"must": [
{"term": {"refs.guid": item["guid"]}},
{"term": {"pubstatus": "usable"}},
{"terms": {"state": ["published", "scheduled"]}},
],
for ref in superdesk.get_resource_service("news").search(
{
"query": {
"bool": {
"must": [
{"term": {"refs.guid": item["guid"]}},
{"term": {"pubstatus": "usable"}},
{"terms": {"state": ["published", "scheduled"]}},
],
},
},
},
})
}
)
]
)

Expand Down Expand Up @@ -680,7 +693,11 @@ def _format_content(self, item, is_broadcast):
elem.tag = "em"

# Remove whitespace and empty tags
if elem.tag in INLINE_ELEMENTS and elem.text is not None and not elem.text.strip():
if (
elem.tag in INLINE_ELEMENTS
and elem.text is not None
and not elem.text.strip()
):
elem.drop_tree()

return sd_etree.to_string(tree, encoding="unicode", method="html")
Expand Down
2 changes: 1 addition & 1 deletion server/cp/output/formatter/ninjs_formatter_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _transform_to_ninjs(self, article, subscriber, recursive=True):
if article.get("extra"):
ninjs["extra"] = article["extra"]
for key, value in ninjs["extra"].items():
if type(value) == dict and "embed" in value:
if isinstance(value, dict) and "embed" in value:
value.setdefault("description", "")

return ninjs
Expand Down

0 comments on commit dc44579

Please sign in to comment.