From d23a1a3417d704781b8b12bb8bbdaa744d94ee05 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Mon, 23 Oct 2023 12:51:16 +0200 Subject: [PATCH] fix formatter for places with missing wikidata id SDNTB-852 --- server/ntb/publish/ntb_nitf.py | 5 +++-- server/ntb/tests/publish/ntb_ninjs_test.py | 15 +++++++++++++++ server/ntb/tests/publish/ntb_nitf_test.py | 11 +++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/server/ntb/publish/ntb_nitf.py b/server/ntb/publish/ntb_nitf.py index 4ac7e08ab..db639d99a 100644 --- a/server/ntb/publish/ntb_nitf.py +++ b/server/ntb/publish/ntb_nitf.py @@ -244,11 +244,12 @@ def _format_place(self, article, docdata): for attrib, keys in mapping: for key in keys: if data.get(key): - if not data.get("wikidata") and key == "altids": + if not data.get("wikidata") and key == "altids" and data.get("altids").get("wikidata"): evloc.attrib[attrib] = data.get("altids", {}).get( "wikidata" ) - else: + break + elif isinstance(data.get(key), str): evloc.attrib[attrib] = data[key] break diff --git a/server/ntb/tests/publish/ntb_ninjs_test.py b/server/ntb/tests/publish/ntb_ninjs_test.py index 28850c121..b98685bd8 100644 --- a/server/ntb/tests/publish/ntb_ninjs_test.py +++ b/server/ntb/tests/publish/ntb_ninjs_test.py @@ -131,6 +131,17 @@ class Ninjs2FormatterTest(TestCase): "name": "Global", "qcode": "Global", }, + { + 'aliases': [], + 'altids': { + 'imatrics': '34017822-d341-3826-ab94-71d226d639c4', + }, + 'name': 'Genève', + 'original_source': None, + 'qcode': '34017822-d341-3826-ab94-71d226d639c4', + 'scheme': 'place_custom', + 'source': 'imatrics', + }, ], "object": [ { @@ -331,6 +342,10 @@ def test_format_item(self): "name": "Global", "literal": "Global", }, + { + "name": 'Genève', + "literal": '34017822-d341-3826-ab94-71d226d639c4', + }, ], "taglines": [ "admin@example.com", diff --git a/server/ntb/tests/publish/ntb_nitf_test.py b/server/ntb/tests/publish/ntb_nitf_test.py index bb13921f1..6dc823090 100644 --- a/server/ntb/tests/publish/ntb_nitf_test.py +++ b/server/ntb/tests/publish/ntb_nitf_test.py @@ -316,6 +316,17 @@ "source": "imatrics", "original_source": "1013", }, + { + 'aliases': [], + 'altids': { + 'imatrics': '34017822-d341-3826-ab94-71d226d639c4', + }, + 'name': 'Genève', + 'original_source': None, + 'qcode': '34017822-d341-3826-ab94-71d226d639c4', + 'scheme': 'place_custom', + 'source': 'imatrics', + }, ], "object": [ {