Skip to content

Commit

Permalink
avoid using place qcode in nitf
Browse files Browse the repository at this point in the history
SDNTB-854
  • Loading branch information
petrjasek committed Oct 24, 2023
1 parent 84adc84 commit 77eabf5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/ntb/publish/ntb_ninjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
4 changes: 3 additions & 1 deletion server/ntb/publish/ntb_nitf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", []):
Expand All @@ -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")
Expand Down
13 changes: 9 additions & 4 deletions server/ntb/tests/publish/ntb_nitf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"), "")

0 comments on commit 77eabf5

Please sign in to comment.