Skip to content

Commit

Permalink
use translations when populating anpa category on ingest (#2666)
Browse files Browse the repository at this point in the history
SDCP-819
  • Loading branch information
petrjasek authored Aug 20, 2024
1 parent 87efa10 commit 91cb177
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions superdesk/io/commands/update_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ def process_anpa_category(item, provider):
# make the case of the qcode match what we hold in our dictionary
item_category["qcode"] = mapped_category[0]["qcode"]
item_category["scheme"] = "categories"
if mapped_category[0].get("translations"):
item_category["translations"] = mapped_category[0]["translations"]
if item.get("language"):
set_subject_name_translation(item_category, item["language"])

except Exception as ex:
raise ProviderError.anpaError(ex, provider)

Expand Down Expand Up @@ -774,4 +779,11 @@ def set_expiry(item, provider, parent_expiry=None):
)


def set_subject_name_translation(subject, language) -> None:
try:
subject["name"] = subject["translations"]["name"][language]
except (KeyError, TypeError):
pass


superdesk.command("ingest:update", UpdateIngest())
9 changes: 8 additions & 1 deletion tests/io/update_ingest_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ def test_subject_to_anpa_category_derived_ingest(self):
"_id": "categories",
"items": [
{"is_active": True, "name": "Australian Weather", "qcode": "b", "subject": "17000000"},
{"is_active": True, "name": "Finance", "qcode": "f"},
{
"is_active": True,
"name": "Finance",
"qcode": "f",
"translations": {"name": {"fr": "Finance FR"}},
},
],
},
{"_id": "genre", "items": [{"qcode": "feature", "name": "feature"}]},
Expand All @@ -399,10 +404,12 @@ def test_subject_to_anpa_category_derived_ingest(self):
for item in items:
item["ingest_provider"] = provider["_id"]
item["expiry"] = utcnow() + timedelta(hours=11)
item["language"] = "fr"

# ingest the items and check the subject code has been derived
self.ingest_items(items, provider, provider_service)
self.assertEqual(items[0]["anpa_category"][0]["qcode"], "f")
self.assertEqual(items[0]["anpa_category"][0]["name"], "Finance FR")

def test_subject_to_anpa_category_derived_ingest_ignores_inactive_map_entries(self):
vocab = [
Expand Down

0 comments on commit 91cb177

Please sign in to comment.