diff --git a/server/ntb/publish/ntb_ninjs.py b/server/ntb/publish/ntb_ninjs.py index c944ffd7a..b82c57ade 100644 --- a/server/ntb/publish/ntb_ninjs.py +++ b/server/ntb/publish/ntb_ninjs.py @@ -159,8 +159,8 @@ def _format_place(self, article) -> List[Dict]: places = [] for place in article["place"]: ninjs_place = { - "name": place.get("name"), - "literal": place.get("qcode"), + "name": place.get("name") or "", + "literal": place.get("qcode") or "", } cv_place = self.places.get(place["qcode"]) diff --git a/server/ntb/publish/ntb_nitf.py b/server/ntb/publish/ntb_nitf.py index db639d99a..4abb7e6e9 100644 --- a/server/ntb/publish/ntb_nitf.py +++ b/server/ntb/publish/ntb_nitf.py @@ -231,7 +231,7 @@ def places(self): def _format_place(self, article, docdata): mapping = ( ("state-prov", ("ntb_parent", "name")), - ("county-dist", ("ntb_qcode", "qcode")), + ("county-dist", ("ntb_qcode", )), ("id", ("wikidata", "altids")), ) for place in article.get("place", []): @@ -252,6 +252,8 @@ def _format_place(self, article, docdata): elif isinstance(data.get(key), str): evloc.attrib[attrib] = data[key] break + else: + evloc.attrib[attrib] = "" def _format_pubdata(self, article, head): pub_date = article["versioncreated"].astimezone(tz).strftime("%Y%m%dT%H%M%S") diff --git a/server/ntb/tests/publish/ntb_nitf_test.py b/server/ntb/tests/publish/ntb_nitf_test.py index 6dc823090..07eea19eb 100644 --- a/server/ntb/tests/publish/ntb_nitf_test.py +++ b/server/ntb/tests/publish/ntb_nitf_test.py @@ -849,7 +849,12 @@ def test_language_empty(self): self.formatter.format(article, {"name": "Test NTBNITF"}) def test_place_imatrics(self): - evloc = self.nitf_xml_imatrics.find("head/docdata/evloc") - self.assertEqual(evloc.get("county-dist"), "Gjerdrum") - self.assertEqual(evloc.get("state-prov"), "Viken") - self.assertEqual(evloc.get("id"), "Q57084") + evloc = self.nitf_xml_imatrics.findall("head/docdata/evloc") + + self.assertEqual(evloc[0].get("county-dist"), "Gjerdrum") + self.assertEqual(evloc[0].get("state-prov"), "Viken") + self.assertEqual(evloc[0].get("id"), "Q57084") + + self.assertEqual(evloc[1].get("county-dist"), "") + self.assertEqual(evloc[1].get("state-prov"), "Genève") + self.assertEqual(evloc[1].get("id"), "")